This chapter provides the information you need to migrate your Gradle 7.x builds to the latest Gradle release. For migrating from Gradle 4.x, 5.x, or 6.x, see the older migration guide first.
We recommend the following steps for all users:
-
Try running
gradle help --scan
and view the deprecations view of the generated build scan.This is so that you can see any deprecation warnings that apply to your build.
Alternatively, you could run
gradle help --warning-mode=all
to see the deprecations in the console, though it may not report as much detailed information. -
Update your plugins.
Some plugins will break with this new version of Gradle, for example because they use internal APIs that have been removed or changed. The previous step will help you identify potential problems by issuing deprecation warnings when a plugin does try to use a deprecated part of the API.
-
Run
gradle wrapper --gradle-version {gradleVersion}
to update the project to {gradleVersion}. -
Try to run the project and debug any errors using the Troubleshooting Guide.
-
Kotlin has been updated to Kotlin 1.5.31.
-
Groovy has been updated to Groovy 3.0.9.
The order in which plugins in the plugins
block were actually applied was inconsistent
and depended on how a plugin was added to the class path. Now the plugins are always applied
in the same order they are declared in the plugins
block which in rare cases might change
behavior of existing builds.
Prior to this version, a dependency substitution target could not be excluded from a dependency graph. This was caused by checking for exclusions prior to performing the substitution. Now Gradle will also check for exclusion on the substitution result.
For up-to-date checks Gradle relies on tracking the state of the inputs and the outputs of a task. Gradle used to ignore unreadable files in the input or outputs to support certain use-cases, although it cannot track their state. Declaring input or output directories on tasks which contain unreadable content has been deprecated and these use-cases are now supported by declaring those inputs or outputs as untracked. Use the @Untracked annotation or the @TaskFilePropertyBuilder.untracked() method to declare untracked inputs or outputs.
When you are using a @Copy
task for copying single files into a directory which contains unreadable files, use the method Copy.ignoreExistingContentInDestinationDir().
Due to CVE-2021-32751, gradle
, gradlew
and start scripts generated by Gradle’s application plugin have been updated to avoid situations where these
scripts could be used for arbitrary code execution when an attacker is able to change environment variables.
You can use the latest version of Gradle to generate a gradlew
script and use it to execute an older version of Gradle.
This should be a transparent for most users; however, there may be changes for Gradle builds that rely on the environment variables JAVA_OPTS
or GRADLE_OPTS
to pass parameters with complicated quote escaping.
Contact us if you suspect something has broken your build and you cannot find a solution.
-
Groovy has been updated to Groovy 3.0.8.
-
Kotlin has been updated to Kotlin 1.5.21.
-
PMD has been updated to PMD 6.36.0.
When using a Java lambda to implement a task action, Gradle cannot track the implementation and the task will never be up-to-date of from the build cache. Since it is easy to add such a task action, using task actions implemented by Java lambdas is now deprecated. See Validation problems for more details how to fix the issue.
When a task input is annotated with @Input
and is not a type Gradle understand directly (like String
), then Gradle uses the serialized form of the input for up-to-date checks and the build cache key.
Historically, Gradle also loads the serialized value from the last execution and then uses equals()
to compare it to the current value for up-to-date checks.
Doing so is error prone, doesn’t work with the build cache and has a performance impact, therefore it has been deprecated.
Instead of using at @Input
on a type Gradle doesn’t understand directly, use @Nested
and annotate the properties of the type accordingly.
-
JaCoCo has been updated to 0.8.7.
Officially, the org.gradle.util
package is not part of the public API.
But, because this package name doesn’t contain the word internal
, many Gradle plugins already consider as one.
Gradle 7.1 addresses the situation and marks the package as public.
The classes that were unintentionally exposed are either deprecated or removed, depending on their external usage.
The following classes have known usages in external plugins and are now deprecated and set for removal in Gradle 8.0:
-
VersionNumber
-
TextUtil
-
WrapUtil
-
RelativePathUtil
-
DistributionLocator
-
SingleMessageLogger
-
ConfigureUtil
ConfigureUtil
is being removed without a replacement. Plugins can avoid the need for using ConfigureUtil
by following our example.
The following classes have only internal usages and were moved from org.gradle.util
to the org.gradle.util.internal
package:
-
Resources
-
RedirectStdOutAndErr
-
Swapper
-
StdInSwapper
-
IncubationLogger
-
RedirectStdIn
-
MultithreadedTestRule
-
DisconnectableInputStream
-
BulkReadInputStream
-
MockExecutor
-
FailsWithMessage
-
FailsWithMessageExtension
-
TreeVisitor
-
AntUtil
-
JarUtil
The following source sets are contributed via an extension with a custom type:
-
groovy
: GroovySourceDirectorySet -
antlr
: AntlrSourceDirectorySet -
scala
: ScalaSourceDirectorySet
The 'idiomatic' DSL declaration is backward compatible:
sourceSets {
main {
groovy {
// ...
}
}
}
However, the return type of the groovy block has changed to the extension type. This means that the following snippet no longer works in Gradle 7.1:
sourceSets {
main {
GroovySourceSet sourceSet = groovy {
// ...
}
}
}
Convention mapping is an internal feature that is been replaced by the Provider API. When mixing convention mapping with the Provider API, unexpected behavior can occur. Gradle emits a deprecation warning when a property in a task, extension or other domain object uses convention mapping with the Provider API.
To fix this, the plugin that configures the convention mapping for the task, extension or domain object needs to be changed to use the Provider API only.
The JacocoMerge
task was used for merging coverage reports from different subprojects into a single report.
The same functionality is also available on the JacocoReport
task.
Because of the duplication, JacocoMerge
is now deprecated and scheduled for removal in Gradle 8.0.
Command line options:
-
-c
,--settings-file
for specifying a custom settings file location -
-b
,--build-file
for specifying a custom build file location
have been deprecated.
Setting custom build file using buildFile property in GradleBuild task has been deprecated.
Please use the dir property instead to specify the root of the nested build. Alternatively, consider using one of the recommended alternatives for GradleBuild task as suggested in Avoid using the GradleBuild task type section.
Setting custom build layout using StartParameter methods setBuildFile(File) and setSettingsFile(File) as well as the counterpart getters getBuildFile() and getSettingsFile() have been deprecated.
Please use standard locations for settings and build files:
-
settings file in the root of the build
-
build file in the root of each subproject
For the use case where custom settings or build files are used to model different behavior (similar to Maven profiles), consider using system properties with conditional logic. For example, given a piece of code in either settings or build file:
if (System.getProperty("profile") == "custom") {
println("custom profile")
} else {
println("default profile")
}
You can pass the profile
system property to Gradle using gradle -Dprofile=custom
to execute the code in the custom
profile branch.
Dependency substitutions using with
method have been deprecated
and are replaced with using
method that also allows chaining.
For example, a dependency substitution rule substitute(project(':a')).with(project(':b'))
should be replaced with
substitute(project(':a')).using(project(':b'))
.
With chaining you can, for example, add a reason for a substitution like this:
substitute(project(':a')).using(project(':b')).because("a reason")
.
-
The JavaCompile.destinationDir property has been deprecated. Use the JavaCompile.destinationDirectory property instead.
-
The GroovyCompile.destinationDir property has been deprecated. Use the GroovyCompile.destinationDirectory property instead.
-
The ScalaCompile.destinationDir property has been deprecated. Use the ScalaCompile.destinationDirectory property instead.
There are several disadvantages of using a flat project structure. One example being that Gradle file-system watching cannot be efficiently used. Because of this, Gradle 7.1 deprecates all layouts that define subprojects outside of a root project directory.
To make this change more visible for plugin author, Gradle 7.1 also deprecates the Settings.includeFlat() method.
Gradle used to have two ways of publishing artifacts.
Now, the situation has been cleared and all build should use the maven-publish
plugin.
The last remaining artifact of the old way of publishing is the Upload
task that has been deprecated and scheduled for removal in Gradle 8.0.
Existing clients should migrate to the maven-publish
plugin.
The concept of conventions is outdated and superseded by extensions. To reflect this in the Gradle API, the following elements are now deprecated:
The internal usages of conventions have been also cleaned up (see the deprecated items below).
Plugin authors migrate to extensions if they replicate the changes we’ve done internally. Here are some examples:
-
Migrate plugin configuration: gradle/gradle#16900.
-
Migrate custom source sets: gradle/gradle#17149.
The convention properties contributed by the base
plugin have been deprecated and scheduled for removal in Gradle 8.0.
The conventions are replaced by the the base { }
configuration block backed by BasePluginExtension.
The old convention object defines the distsDirName
, libsDirName
and archivesBaseName
properties with simple getter and setter methods.
Those methods are available in the extension only to maintain backwards compatibility.
Build scripts should solely use the properties of type Property
:
base {
archivesName = 'customBase'
distsDirectory = layout.buildDirectory.dir('custom-dist')
libsDirectory = layout.buildDirectory.dir('custom-libs')
}
ApplicationPluginConvention was already listed as deprecated in the documentation. Now, it is officially annotated as deprecated and scheduled for removal in Gradle 8.0.
The convention properties contributed by the java
plugin have been deprecated and scheduled for removal in Gradle 8.0.
They are replaced by the the properties of JavaPluginExtension which can we configured in the java {}
block.
Some of the core Gradle plugins declare configurations that are used by the plugin itself and are not meant to be published or consumed by another subproject directly. Gradle did not explicitly prohobit this. Gradle 7.1 deprecates consumption of those configurations and this will become an error in Gradle 8.0.
The following plugin configurations have been deprecated for consumption:
plugin | configurations deprecated for consumption |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If your use case needs to consume any of the above mentioned configurations in another project, please create a separate consumable configuration that extends from the internal ones. For example:
plugins {
id("codenarc")
}
configurations {
codenarc {
// because currently this is consumable until Gradle 8.0 and can clash with the configuration below depending on the attributes set
canBeConsumed = false
}
codenarcConsumable {
extendsFrom(codenarc)
canBeConsumed = true
canBeResolved = false
// the attributes below make this configuration consumable by a `java-library` project using `implementation` configuration
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment, TargetJvmEnvironment.STANDARD_JVM));
}
}
}
ProjectReportsPluginConvention is now deprecated and scheduled for removal in Gradle 8.0. Clients should configure the project report tasks directly. Also, tasks.withType(…).configureEach(…) can be used to configure each task of the same type (HtmlDependencyReportTask
for example).
WarPluginConvention is now deprecated and scheduled for removal in Gradle 8.0. Clients should configure the war
task directly. Also, tasks.withType(War.class).configureEach(…) can be used to configure each task of type War
.
EarPluginConvention is now deprecated and scheduled for removal in Gradle 8.0. Clients should configure the ear
task directly. Also, tasks.withType(Ear.class).configureEach(…) can be used to configure each task of type Ear
.
The following source set interfaces are now deprecated and scheduled for removal in Gradle 8.0:
Clients should configure the sources with their plugin-specific configuration:
- groovy
: GroovySourceDirectorySet
- antlr
: AntlrSourceDirectorySet
- scala
: ScalaSourceDirectorySet
For example, here’s how you configure the groovy sources from a plugin:
GroovySourceDirectorySet groovySources = sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
groovySources.setSrcDirs(Arrays.asList("sources/groovy"));
When Gradle first introduced artifact transforms, it used the base class ArtifactTransform
for implementing them.
Gradle 5.3 introduced the interface TransformAction
for implementing artifact transforms, replacing the previous class ArtifactTransform
and addressing various shortcomings.
Using the registration method DependencyHandler.registerTransform(Action) for ArtifactTransform
has been deprecated.
Migrate your artifact transform to use TransformAction
and use DependencyHandler.registerTransform(Class, Action) instead.
See the user manual for more information on implementing TransformAction
.