Gradle: Build Automation for the JVM, Android, and C/C++
Gradle | Gradle Features
# info and debug log
gradle -i task
gradle -d task
# show project properties
gradle properties
Gradle Release Notes
Gradle User Guide
Gradle | Gradle Tutorials and Guides
Gradle User Guide ä¸æ–‡ç‰ˆ of older version
An introduction to Gradle for complete beginners - Android Authority
Building C++ applications and libraries
Building Java & JVM projects
Gradle in 60 Seconds
Using Gradle Build Variants - Tuts+ Code Tutorial
The Ins and Outs of Gradle
Trainings | Gradle Enterprise
Blog | Gradle Enterprise
Dependency Management with Gradle Part 1 - Fundamentals | Gradle Enterprise
Build Best Practicess | Gradle Enterprise
Build performances | Gradle Enterprise
CircleCI cache key over many files – Chris Banes – Medium
The one Gradle trick that supersedes all the others generate scans for debugging and support
DSL
The Power of Gradle Kotlin DSL - Kotlin Expertise Blog
Gradle Kotlin DSL Primer
A Groovy Build Script Primer
Gradle Kotlin DSL 1.0
The Road to Gradle Script Kotlin 1.0
Kotlin Meets Gradle
gradle/kotlin-dsl: Kotlin language support for Gradle build scripts
Migrating build logic from Groovy to Kotlin
Migrating Android build scripts from Groovy to Kotlin DSL
The New Way of Writing Build Gradle with Kotlin DSL
Anti-pattern
// don't use this
apply plugin: 'kotlin'
// use this
plugins {
kotlin("jvm") version "1.3.21"
}
Examples
gradle/subprojects/docs/src/samples at master · gradle/gradle
kotlin-dsl/samples at master · gradle/kotlin-dsl
JetBrains/kotlin: The Kotlin Programming Language Kotlin project uses Kotlin DSL
Groovy vs Kotlin
I prefer Kotlin over Groovy:
- Kotlin is more modern, has more potential and more worthy to learn than Groovy
- Parentheses for function invocation is optional in Groovy, making it even harder to distingush between setting field or calling function
repositories {
jcenter()
}
configurations {
ktlint
}
dependencies {
ktlint "com.github.shyiko:ktlint:0.29.0"
}
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.github.shyiko.ktlint.Main"
args "src/**/*.kt"
}
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
main = "com.github.shyiko.ktlint.Main"
args "-F", "src/**/*.kt"
}
allprojects {
apply from: "$rootDir/ktlint.gradle"
}
Plugins
Wrapper
A local copy of Gradle can be downloaded in ./gradle/
, a wrapper gradlew
will be created. This allows for version controlling Gradle tool and self-contained build environment.
# with gradle installed on host
gradle init --dsl kotlin
gradle wraper --gradle-version=5.3.1
# even better using gradle Docker image
docker run --rm -u $(id -u):$(id -g) \
-v "$PWD":/home/gradle/project -w /home/gradle/project \
gradle gradle init --dsl kotlin
docker run --rm -u $(id -u):$(id -g) \
-v "$PWD":/home/gradle/project -w /home/gradle/project \
gradle gradle wrapper --gradle-version=5.3.1
Lifecycle
Build Lifecycle
Understanding Gradle: the Build Lifecycle – ProAndroidDev
Cédric Champeau's blog: Gradle myth busting: lifecycle
Tasks
# show tasks
gradle tasks
# also show tasks not in task group
gradle tasks --all
# filter by task group
gradle tasks --group="build setup"
# show details of task
gradle -q help --task <task>
# upload build scan to https://scans.gradle.com/
# https://gradle.com/build-scans/
gradle --scan <task>
Milti project
# list sub-projects, displayed in a hierarchy
gradle projects
Docker plugins
palantir/gradle-docker: a Gradle plugin for orchestrating docker builds and pushes.
Gradle Docker Plugin User Guide & Examples
bmuschko/gradle-docker-plugin: Gradle plugin for managing Docker images and containers.
avast/gradle-docker-compose-plugin: Simplifies usage of Docker Compose for integration testing in Gradle environment.
Comparison
Gradle vs Maven Comparison
Gradle vs. Maven - DZone Java
Java Build Tools: Ant vs Maven vs Gradle | Technology Conversations
Android adoption
New Build System - Android Tools Project Site
Build System Overview | Android Developers