类型“JavaCompile”属性“options.compilerArgumentProviders.apt$0.name”缺少输入或输出注释。升级到 Gradle 7 后出错

Posted

技术标签:

【中文标题】类型“JavaCompile”属性“options.compilerArgumentProviders.apt$0.name”缺少输入或输出注释。升级到 Gradle 7 后出错【英文标题】:Type 'JavaCompile' property 'options.compilerArgumentProviders.apt$0.name' is missing an input or output annotation. error after upgrading to Gradle 7 【发布时间】:2021-07-08 23:05:45 【问题描述】:

升级到 Gradle 7.0 并进行构建后,我遇到以下故障:

> 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.

我尝试使用--stacktrace,但没有得到任何帮助。 这里的事情是我不确定在哪里寻找以解决这个问题,因为它没有提到 build.gradle 文件中的任何行或其他关于在哪里寻找的提示。

【问题讨论】:

您使用的是第三方apt plugin吗?如果是这样,你可能不应该 - 它已经过时了。 @BjørnVester,你是对的。这就是问题所在。我使用的是旧的/已弃用的插件(已删除)。如果您愿意,可以将其作为答案,我将其作为解决方案。 【参考方案1】:

对于 Gradle 7.2.* 和 Intellij Idea 只需摆脱 net.ltgt.aptnet.ltgt.apt-idea,更多信息请参阅 https://github.com/tbroyer/gradle-apt-plugin

我有 apply plugin: 'net.ltgt.apt-idea' 并收到此错误

【讨论】:

【参考方案2】:

只需删除所有 net.ltgt.apt 依赖项。您将不再需要它,因为它的功能现在可以在 Gradle 中本地使用。

更多详情: 来自插件 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.

【讨论】:

【参考方案3】:

对于任何有同样问题的人:正如Bjørn 所指出的,apt 插件是我的 Gradle 构建文件中的罪魁祸首。我删除了通用的 (id "net.ltgt.apt") 和 IntelliJ 的 (id "net.ltgt.apt-idea"),然后我的构建文件再次工作。

【讨论】:

Eclipse 用户注意:我使用的是net.ltgt.aptnet.ltgt.apt-eclipse,只删除net.ltgt.apt 似乎并不能解决问题。我切换到似乎可以工作的com.diffplug.eclipse.apt 插件:plugins.gradle.org/plugin/com.diffplug.eclipse.apt

以上是关于类型“JavaCompile”属性“options.compilerArgumentProviders.apt$0.name”缺少输入或输出注释。升级到 Gradle 7 后出错的主要内容,如果未能解决你的问题,请参考以下文章

Android Studio解决Java程序输出中文乱码

使用类型中的“in”键入具有计算属性的类型

android studio中文乱码问题

gradle编译出现gbk无法映射字符

如何将 kotlin 类添加到 gradle JavaCompile 任务

Android Studio中的Java控制台中出现乱码问题?