Its an open source build tool written in Java, Groovy, Kotlin. Gradle is more popular because its extensible and customizable.
How to configure Gradle?
- Download recent version of gradle from gradle.org.
- Add the gradle bin path to your system path and set GRADLE_HOME
- .gradle - is the local repository where all the gradle files will be stored.
- build.gradle - build file to define our plugins, dependencies, repositories.
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?
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
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
- Right click on task in gradle tab in eclipse and click 'edit configuration'. Enter -P <propertyName> in parameters
- Run in command line with gradle <taskName> -P <propertyName>
