Java 现在必须显式声明注释处理器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46963498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:31:16  来源:igfitidea点击:

Annotation processors must be explicitly declared now

javaandroid

提问by Ankit Srivastava

Error:Execution failed for task ':laMusique2May2016:javaPreCompileRelease'.
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - auto-value-1.1.jar (com.google.auto.value:auto-value:1.1)
  Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
  See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

I am seeing this issue, but the problem is auto-value-1.1.jar is not in my gradle files

我看到了这个问题,但问题是 auto-value-1.1.jar 不在我的 gradle 文件中

采纳答案by Jon

You should explicitly add annotation processors in gradle. Putting the following in your gradle dependencies should fix it:

您应该在 gradle 中显式添加注释处理器。将以下内容放在您的 gradle 依赖项中应该可以修复它:

annotationProcessor 'com.google.auto.value:auto-value:1.1'


However, as others have already mentioned, you should probably figure out which of your existing dependencies was using auto-value to assert whether or not you really need it. Annotation processors ultimately slow down your build time so don't include it if it's unnecessary.

但是,正如其他人已经提到的,您可能应该弄清楚您现有的哪些依赖项正在使用自动值来断言您是否真的需要它。注释处理器最终会减慢您的构建时间,因此如果没有必要,请不要包含它。

回答by krishnamurthy

Even i had the same problem and finally i solved my problem by adding this to app level gradle file

即使我遇到了同样的问题,最后我还是通过将它添加到应用程序级别的 gradle 文件中解决了我的问题

android{
....
    defaultConfig{
....
    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }
}
buildTypes {
...
}

hope its solved someone's problem

希望它解决了某人的问题

回答by wdanxna

Adding annotationProcessor dependencies not work for me, instead I drop this line inside build.gradleat arbitrary places works:

添加 annotationProcessor 依赖项对我不起作用,而是我将这一行放在build.gradle任意位置工作:

android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true

android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true

回答by erluxman

Annotation processors can be declaredwith annotationProcessorinstead ofimplementation/compilelike we used to declare earlier.

注释处理器可以用 来声明annotationProcessor而不是implementation/compile像我们之前声明的那样。

implementation 'com.google.auto.value:auto-value:1.1' 

compile 'com.google.auto.value:auto-value:1.1' 

Should be replaced with

应该换成

annotationProcessor 'com.google.auto.value:auto-value:1.1'

回答by CyxouD

For me, this issue happened because jitpackwasn't placed as the last entry in root grade.

对我来说,发生这个问题是因为jitpack没有作为根等级的最后一个条目。

allprojects {
    repositories {
        // ... other repositories
        maven { url "https://jitpack.io" }
    }
}

The solution was taken from @hotchemi comment in https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/535#issuecomment-432190926

该解决方案取自https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/535#issuecomment-432190926 中的@hotchemi 评论