Developers want builds to be fast, correct and reliable. In order to improve the reliability and correctness of Gradle builds, Gradle 7 has introduced stricter validation checks for tasks. This means that validation warnings in Gradle 6 have now turned in to errors in Gradle 7.
When upgrading to Gradle 7, you may encounter an issue that some of your previously working plugins may not pass the validation and therefore fail your build.
The error message in your build upon upgrading to Gradle 7 could look like this:
* What went wrong: A problem was found with the configuration of task ':incompatibleTask' (type 'IncompatibleTask'). - Type 'com.osacky.replace.example.IncompatibleTask' property 'foo' is missing an input or output annotation. Reason: A property without annotation isn't considered during up-to-date checking. Possible solutions: 1. Add an input or output annotation. 2. Mark it as @Internal. Please refer to https://docs.gradle.org/7.0.2/userguide/validation_problems.html#missing_annotation for more details about this problem.
For tasks defined within your own build, the error message is actionable.
To fix this problem, you need to annotate the property with the appropriate annotation, for example
@InputDirectoryfor a property representing an input directory, or
@OutputDirectoryfor a property representing an output directory.
Alternatively, if the property is internal, that is to say that it shouldn’t participate in up-to-date checking (it’s not an input or an output), then you need to annotate it with
For tasks defined using the so-called ad-hoc api, you can also add the input and output declarations.
For third party plugins, it isn't so clear what to do. First, check to see if there is an update to the Gradle plugin which makes the task compatible with Gradle 7.
If no such updated version exists, this is a great time to get involved in an open source project. You can file an issue for that third party plugin to add the proper annotation to the task definition.
Even better, you can also submit a pull request to add the proper annotations.
For those unmaintained plugins, there is another option. You can redefine the task in your
buildSrc directory and declare the proper annotations. Here is how to do this.
First, if you have not already done so, create a
buildSrc directory in your project and configure the
build.gradle file. Here is a sample.
Third, add the missing annotation to the missing property defined in the task.
Finally, run your Gradle build and enjoy!
To run the sample,
To see the incompatible task fail the build in an integration test, run
Thanks to Tony (@autonomousapps ) for proofreading this blog post.
The opinions expressed in this post are the opinions of Nelson Osacky and not of his employer.