Thursday, March 11, 2021

Gradle

http://downloads.gvsig.org/download/people/jjdelcerro/docs/The%20Gradle%20build%20system%20-%20Tutorial%20-%20Lars%20Vogel,%20Simon%20Scholz.pdf




To install Gradle use the below link

https://gradle.org/install/

To check gradle version

gradle -v

Sample gradle file and name should be "build.gradle"

task hello {
   doLast {
      println 'tutorialspoint'
   }
}

run the below command gradle -q hello --> hello is the task which we have mentioned in the file 

<< --> Is deprecated and removed in Gradle 5 version.


The Gradle script mainly uses two real Objects; one is Project Object and another one is Script Object.

Project Object − Each script describes about one or multiple projects. While in the execution, this script configures the Project Object. You can call some methods and use property in your build script which are delegated to the Project Object.

Script Object − Gradle takes script code into classes, which implements Script Interface and then executes. This means that of all the properties and methods declared by the script interface are available in your script.

The following table defines the list of standard project properties. All these properties are available in your build script.

Sr. No. Name Type Default Value
1 project Project The Project instance
2 name String The name of the project directory.
3 path String The absolute path of the project.
4 description String A description for the project.
5 projectDir File The directory containing the build script.
6 buildDir File projectDir/build
7 group Object Unspecified
8 version Object Unspecified
9 ant AntBuilder An AntBuilder instance



Build cache

https://guides.gradle.org/using-build-cache/


To list the Task in gradle use the below command 

gradle -p <<projectname>> tasks



buildscript should be top of plugins 


Difference between apply from and apply plugin
 https://stackoverflow.com/questions/29378249/difference-apply-from-vs-apply-plugin

To run main class using the Gradle task 
https://www.baeldung.com/gradle-run-java-main

Explains about SourceSet 
https://www.baeldung.com/gradle-source-sets

dolast in Gradle 
https://discuss.gradle.org/t/what-is-dolast-for/27731/3

******************************************************************

few options to verify how to speed up gradle builds

https://medium.com/@shelajev/6-tips-to-speed-up-your-gradle-build-3d98791d3df9
https://dzone.com/articles/how-speed-your-gradle-build-90
http://kevinpelgrims.com/blog/2015/06/11/speeding-up-your-gradle-builds/

Gradle Daemon

https://docs.gradle.org/current/userguide/gradle_daemon.html

gradle --status --> to know the daemon status
gradle --stop --> To stop the daemon
gradle daemon will start when we trigger the build

Gradle settings 

https://docs.gradle.org/current/javadoc/org/gradle/api/initialization/Settings.html#includeFlat-java.lang.String...-

******************************************************************
Gradle Lifecycle : (https://docs.gradle.org/current/userguide/build_lifecycle.html)
   It has three phases : initialization, configuration, and execution

1. During Initialization, Gradle decides which projects are to participate in the build.

2. During Configuration, task objects are assembled into an internal object model, usually called the DAG (for directed acyclic graph).

3. During Execution, build tasks are executed in the order required by their dependency relationships.

*******************************************************************
Profile is option to know which Task will take how much time 

gradle -p nvkidsframework build --profile


Gradle Daemon 

https://riptutorial.com/gradle/example/11912/use-the-gradle-daemon


To start the gradle daemon just give the command 
   gradle -- daemon

*********************************************************
gradle to create a wrapper 

https://docs.gradle.org/current/userguide/gradle_wrapper.html

https://docs.gradle.org/current/dsl/org.gradle.api.Project.html


to show all task in build.gradle use the below command 
gradle Tasks --all 

to show the task in custom build.gradle file the nuse the below command 

gradle -b pavanbuild.gradle Tasks --all

Task we have three 
  dependson
  finializedBy
  shouldRunAfter

https://www.tutorialandexample.com/gradle-tasks/

Logging Levels in Gradle 

println = quiet

-q
         Error 
        Quiet
default   
    Warning
    Lifecycle 
-i
    Info 
-d 
    Debug 

To view stack trace use the below 

 --stacktrace  or -s
--full-stacktrace or - S

**********************************************************************

gradle init 

in the command we have initiated Task init. Which created following folder and fiels 

.gradle
gradle
gradlew
gradlew.bat

to list task in gradle use the below command 
gradle tasks




Gradle everything is based on the Project and Task 

     Project
     Task

Gradle Task 
     Task is a single unit of work that a build performs
     These tasks can be compiling classes, creating a JAR, Generating Javadoc, and publishing some archives to a repository and more.
     Single atomic piece of work for a build process

Gradle Project
   In Gradle, A project can be a library JAR or a web application. It may also serve a distribution ZIP, which is assembled from the JARs produced by other projects.
   A project could be deploying our application to test or production environments. Each project in Gradle is made up of one or more tasks.


Gradle sections in build.gradle

    plugins
    repositories  --> to download the jar we will use this. we can download from Maven/Ivy/file
    dependencies --> jar dependency 

Repositories

Various options to configure repositories

repositories {
    mavenCentral()
}

repositories {
    maven {
        url "https://repo.maven.apache.org/maven2/"
    }
}

repositories {
    maven("http://jcenter.bintray.com/")
}

To use local library with maven style

repositories {
maven {
        url = file('../libs/repository')
    }
}

To load library from a local directory
repositories {        
     flatDir {
       dirs 'libs'
   }
    flatDir {
       dirs 'libs', 'libs2'
   }
}

Ivy Repository

repositories {
    ivy {
        url "https://repo.mycompany.com/repo"
    }
}

To define more than one repository

respositories {
    maven("https://repo.maven.apache.org/maven2/")
    jcenter{
        url "http://jcenter.bintray.com/"
    }
}
******************************************************************



Plugins in Gradle 


Two types of Plugins 
  a. Script Plugin
  b. Binary Plugin

No comments:

Post a Comment