Thursday, June 4, 2020

Lets Learn Gradle !

What is Gradle?
Its  an open source build tool written in Java, Groovy, Kotlin. Gradle is more popular because its extensible and customizable.

How to configure Gradle?
  1. Download recent version of gradle from gradle.org. 
  2. Add the gradle bin path to your system path and set GRADLE_HOME
  3. .gradle - is the local repository where all the gradle files will be stored. 
  4. build.gradle - build file to define our plugins, dependencies, repositories.
Gradle Components
Build file consists of many projects and each project can contain many tasks. Build -> Projects -> Tasks

Tasks
Tasks can be default or custom tasks. 
Default Tasks - init, wrapper, buildEnvironment, assemble, build, clean, javadoc etc

How do you run tasks?
gradle <taskName>

Define Custom Tasks in build.gradle
task <taskName> {
   group "customTaskGroup"                         -------> Group Task Name
   description "desc"                                       -------> Task Description
   doFirst {}                                                    -------> Perform this first before starting the task
   doLast { println "this is custom task" }      -------> Perform this last after the task execution
}


Define a copy task 
task <taskName>(type: Copy) {         -------------> type can vary depending on the need. 
from ''                                                  -------------> Source directory to copy the files from
into ''                                                   --------------> Destination directory for file copy
}

Build a zip
task <taskName>(type: Zip) {
         from ="E:\someData"
        destinationDir = file ("<fileName>")
        archiveName = "<zipName>"

}

How to skip task 
<taskName>.onlyIf {
  project.hasProperty('<taskName>')
}

How to provide task dependencies
task <taskName>(dependsOn: <taskName>)

Project Properties
  1. Right click on task in gradle tab in eclipse and click 'edit configuration'. Enter -P <propertyName> in parameters
  2. Run  in command line with gradle <taskName> -P <propertyName>

No comments:

Post a Comment

Lets Learn Gradle !

What is Gradle? Its  an open source build tool written in Java, Groovy, Kotlin. Gradle is more popular because its extensible and customiza...