Gradle, a comprehensive polyglot build tool, has released version 4.7 with new features such as:
- Incremental annotation processing
- Java 10 runtime support
- Grouped non-interactive console logs
- Re-run failed tests first for quicker feedback
- Kotlin DSL 0.16, featuring new pre-compiled script plugins
We examine a few of these features here.
Incremental Annotation Processing
Gradle's incremental Java compiler, available since version 2.1, has been enhanced to include incremental processing of annotations. Gradle supports two types of annotation processors for incremental compilation: isolating where annotated elements evaluated in isolation, and aggregating where multiple annotated elements aggregated into one or more output files. All other types of annotation processors will trigger a full recompile of annotations.
The example below demonstrates how to add a Dagger annotation processor to a build.gradle
file:
dependencies {
// the Dagger compiler will only be found on the annotation class path
annotationProcessor 'com.google.dagger:dagger-compiler:2.8'
// the Dagger library is still required on the compile class path
implementation 'com.google.dagger:dagger:2.8'
}
Non-Interactive Console Logs
Gradle supports two console modes: plain used in IDEs or a CI build agents, and rich used on the command line. Prior to this release, the output from plain mode (as shown in the example below using Gradle 4.4 within IntelliJ IDEA) didn't have the same organized output from rich mode.
In this new release, both plain and rich modes produce the same output. As shown in the command line example below, log information produced by a Gradle task is now grouped together and headers are output preceded with > Task
.
Kotlin DSL
Gradle now supports Gradle Kotlin DSL version 0.16.3 featuring precompiled Kotlin DSL scripts with support for Kotlin version 1.2.31 and Java 10, better integration with IntelliJ IDEA, and a more consistent API.
As defined in the release notes:
A precompiled script plugin is a Kotlin script compiled as part of a regular Kotlin source-set, meant to be consumed as a binary Gradle plugin whose identifier is automatically derived from its file name and optional package declaration.
The use of precompiled scripts is enabled in a build.gradle
file:
plugins {
'java-gradle-plugin'
'kotlin-dsl'
}
apply<org.gradle.kotlin.dsl.plugins.precompiled.PrecompiledScriptPlugins>()
Once enabled, scripts defined in src/main/kotlin
is automatically exposed as a normal Gradle plugin. In the example below, a script defined as my-plugin.gradle.kts
will be known to Gradle simply as my-plugin
and may subsequently be used in the build.gradle
file.
Languages supported by Gradle include:
- Java
- C++
- Python ({py}gradle)
- JavaScript
- Clojure
- Scala
Resources
- Gradle's YouTube Channel
- Incremental Compilation, the Java Library Plugin, and Other Performance Features in Gradle 3.4 by Cédric Champeau (February 25, 2017)
- Gradle Kotlin DSL Tutorial by Nick Apperley (January 2, 2018)