Type 'JavaCompile' property 'options.compilerArgumentProviders.apt$0.name' is missing an input or output annotation. error after upgrading to Gradle 7
Asked Answered
I

3

26

After upgrading to Gradle 7.0 and making a build, I'm getting following failure:

> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':compileJava' (type 'JavaCompile').
  - Type 'JavaCompile' property 'options.compilerArgumentProviders.apt$0.name' 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/userguide/validation_problems.html#missing_annotation for more details about this problem.
  - Type 'JavaCompile' property 'options.compilerArgumentProviders.apt$0.publicType' 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/userguide/validation_problems.html#missing_annotation for more details about this problem.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

I tried with --stacktrace but got no help from it. Thing here is that I'm not sure where to look in order to solve this as it doesn't mention any line in build.gradle file or some other hint as to where to look.

Intractable answered 13/4, 2021 at 21:23 Comment(2)
Are you using the third-party apt plugin? If so, you probably shouldn't - it's obsolete.Nickolenicks
@BjørnVester, you were right. That was the issue. I was using an old/deprecated plugin (which I removed). If you want you can put it as answer and I will put it as solution.Intractable
B
29

For anybody with the same issue: As noted by Bjørn, the apt plugin was the culprit in my Gradle build file. I removed the generic one (id "net.ltgt.apt") and the IntelliJ one (id "net.ltgt.apt-idea"), and my build file worked again.

Blenny answered 15/4, 2021 at 17:51 Comment(1)
Note for eclipse users: I was using net.ltgt.apt and net.ltgt.apt-eclipse, only removing net.ltgt.apt doesn't seem to solve the problem. I switched to the com.diffplug.eclipse.apt plugin which seems to work: plugins.gradle.org/plugin/com.diffplug.eclipse.aptProfessed
J
14

Just drop all of the net.ltgt.apt dependencies. You will not need it anymore because, it's features are now available natively in Gradle.

More details: From the plugin README.md (https://github.com/tbroyer/gradle-apt-plugin#readme)

The goal of this plugin was to eventually no longer be needed, being superseded by built-in features. This has become a reality with Gradle 5.2 and IntelliJ IDEA 2019.1. tl;dr: this plugin is obsolete, don't use it. If you're using Eclipse though, continue reading.

It originally did a few things to make it easier/safer to use Java annotation processors in a Gradle build. Those things are now available natively in Gradle, so what's this plugin about?

If you use older versions of Gradle (pre-4.6), you can still benefit from those features:

    it ensures the presence of configurations for your compile-time only dependencies (annotations, generally) and annotation processors, consistently across all supported Gradle versions;
    automatically configures the corresponding JavaCompile and GroovyCompile tasks to make use of these configurations, when the java or groovy plugin is applied.

With recent versions of Gradle (between 4.6 and 5.1), this plugin will actually only:

    add some DSL to configure annotation processors; it is however recommended to directly configure the tasks' options.compilerArgs;
    backport the sourceSet.output.generatedSourcesDirs Gradle 5.2 API;
    configure JavaCompile and GroovyCompile tasks' options.annotationProcessorGeneratedSourcesDirectory with a sane default value so you can see the generated sources in your IDE and for debugging, and avoid shipping them in your JARs.
Joshuajoshuah answered 16/8, 2021 at 13:48 Comment(1)
This answer is half correct and half wrong. If you are using Eclipse, you would still need this plugin.Deontology
B
4

For Gradle 7.2.* and Intellij Idea just get rid from net.ltgt.apt or net.ltgt.apt-idea, see for more https://github.com/tbroyer/gradle-apt-plugin

I had apply plugin: 'net.ltgt.apt-idea' and got this error

Baneful answered 25/11, 2021 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.