The Gradle team has released Gradle 8.0 featuring a reduction in the build duration and an improved Kotlin DSL that supports Kotlin 1.8 and Java 11 features in the build scripts.
Kotlin DSL, first introduced in 2018, may be used as an alternative to the Groovy DSL and offers improved content assistance, refactoring and documentation in supported IDEs such as IntelliJ, Eclipse, Apache NetBeans and Visual Studio Code. The latest release allows .gradle.kts scripts to use Java 11 features instead of Java 8.
An interpreter is now used for the declarative plugins {}
block inside .gradle.kts scripts which reduces the compilation time by about 20%. Version catalog aliases for plugins, such as alias(libs.plugins.mavenPublish)
, and type-safe plugin declarations, such as `my-plugin`
, are not yet supported by the interpreter.
The embedded Kotlin was upgraded to 1.8.10 and the Kotlin DSL now supports the Kotlin API Level 1.8 instead of 1.4. Gradle 8 supports Kotlin Gradle Plugin 1.6.10 and newer, however a lower Kotlin language version might be used, without support, by changing the language version and API version setting inside the Kotlin compile
task. Gradle 8 supports Android Gradle Plugin 8 and newer, or 7.3 and newer, when specifying the property: android.experimental.legacyTransform.forceNonIncremental=true
.
Gradle now uses the directory hierarchy of included builds to prevent conflicts. Consider, for example, the following directory layout:
settings.gradle
levelOneDirectory
settings.gradle
levelTwoDirectory
settings.gradle
Previously, the level levelTwoDirectory
directory could be compiled with gradle :levelTwoDirectory:compileJava
, but now it should be compiled with gradle :levelOneDirectory:levelTwoDirectory:compileJava
.
Tasks of a buildSrc
build may now be run directly on the command line. For example, gradle buildSrc:build
may be used to run the build
task in the buildSrc
build. The new release allows the buildSrc
to include other builds by defining the pluginManagement {includeBuild(anotherBuildDirectory)}
or includeBuild(anotherBuildDirectory)
in the buildSrc/settings.gradle.kts or buildSrc/settings.gradle settings scripts. Tests for buildSrc
are no longer executed automatically as the build
task is no longer run.
The Configuration cache is an incubating feature to reduce the build time by caching the result of the configuration phase and using the cache of subsequent builds. Gradle recommends starting with caching simple tasks first and, if successful, try more advanced tasks. By default, the cache is disabled but it may be enabled with the gradle --configuration-cache
command of by adding the org.gradle.unsafe.configuration-cache=true
property to the gradle.properties file. This release automatically runs tasks in parallel from the first build whenever the configuration cache is enabled.The retention period may now be configured, in order to cleanup the cache in Gradle user home after a specific amount of days:
beforeSettings { settings ->
settings.caches {
downloadedResources.removeUnusedEntriesAfterDays = 45
}
}
The string format of JavaVersion
used for sourceCompatibility
and targetCompatibility
no longer contains the 1. prefix for Java 9 and newer. Gradle 8.0 supports Java versions 1.8, 9, 10 and 11 instead of the Gradle 7.6 equivalents 1.8, 1.9, 1.10 and 11.
Release 8.0.1 is the first patch release and the Gradle team recommends using the latest minor version. The GitHub releases page lists all the available versions.
The latest Gradle release may be installed via SDMAN! with the sdk install gradle 8.0.1
command, via Homebrew with the brew install gradle
command or as a ZIP file via the Gradle Releases page.
Gradle recommends running the gradle help --scan
command and viewing the deprecations section of the report before upgrading. After that, the plugins should be updated and, finally, the gradle wrapper --gradle-version 8.0.1
command may be used to update the application to Gradle 8.0.1. The Troubleshooting Builds guide may be used to resolve build issues. More information on upgrading an application from Gradle 7.0 to 8.0 can be found in the user guide.
Gradle now displays an error, instead of a warning, when using the finalizedBy
, mustRunAfter
or shouldRunAfter
methods. Invalid Java toolchain configurations and automatic downloads without providing repositories now result in an error, which may be resolved by following the user manual.
Gradle 8 removed the --add-opens
argument to open JDK modules, java.base/java.util
and java.base/java.lang
, for Gradle workers. This means the workers, by default, can no longer use the reflection functionality from the JDK internals. Warnings and errors displayed by tools, extensions and plugins can be resolved by updating them.
Configuring the test framework after specifying the test options now produces an error:
test {
options {
}
useJUnitPlatform()
}
Which may be resolved by using the JVM Test Suite Plugin, or by configuring the test framework before specifying the test options:
test {
useJUnitPlatform()
options {
}
}
Various API's, methods and features have been removed and the complete list of changes, about the latest release, can be found in the Gradle 8.0 Release Notes.