$ viĀ build.gradle
task helloWorld { doLast { println "Hellow World" <-- groovy } } |
Run it
$ gradle hellowWorld
Issue the following command to create the wrapper
$ gradle wrapper
Store the wrapper with your source code
Example settings.gradle file
rootProject.name = "starter-example" |
Example gradle.properties file
org.gradle.logging.level = info version = 1.0.0 |
Use the variable in your build.gradle file like so:
task helloWorld { doLast { println "Hellow World, version = " + version } } |
We can add dependsOn to the task to make it depend on the other.
task copyDocs(type: Copy) { from "src" into "build/docs" include "**/*.md" includeEmptyDir = false } task createZip(type: Zip) { from "build/docs" archiveFilename = "docs.zip" destinationDirectory = file("build/dist") dependsOn copyDocs } |
To see the order without executing the tasks, add --dry-run to the end.
$ gradle hellowWorld --dry-run |
Another way to visualize the gradle tree you can use gradle-task-tree.
SeeĀ https://github.com/dorongold/gradle-task-tree
List all available tasks
$ gradle tasks --all |
task copyDocs(type: Copy) { from "src" into "build/docs" include "**/*.md" includeEmptyDir = false } |
task createZip(type: Zip) { from "build/docs" archiveFilename = "docs.zip" destinationDirectory = file("build/dist") } |
Initialization Phase
Configuration Phase
Execution Phase
Configuration Logic
Execution Logic
web-service/build.gradle
dependencies { implementation project(':utils') implementation project(':api') } |
Reference | URL |
---|---|
User Manual | https://docs.gradle.org/current/userguide/userguide.html |
Multi-Project Builds | https://docs.gradle.org/current/userguide/intro_multi_project_builds.html |
Dependencies | https://docs.gradle.org/current/userguide/declaring_dependencies.html#declaring-dependencies |
The Java Plugin | https://docs.gradle.org/current/userguide/java_plugin.html |