Java Gradle 已弃用 lombok 的注释处理器警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50202843/
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-10 23:29:29  来源:igfitidea点击:

Gradle deprecated annotation processor warnings for lombok

javagradlewarningslombokannotation-processing

提问by Bohemian

After upgrading to gradle 4.7, my previously warning-free build now emits this warning:

升级到 gradle 4.7 后,我以前的无警告构建现在发出此警告:

The following annotation processors were detected on the compile classpath: 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor' and 'lombok.launch.AnnotationProcessorHider$ClaimingProcessor'. Detecting annotation processors on the compile classpath is deprecated and Gradle 5.0 will ignore them. Please add them to the annotation processor path instead. If you did not intend to use annotation processors, you can use the '-proc:none' compiler argument to ignore them.

在编译类路径上检测到以下注释处理器:“lombok.launch.AnnotationProcessorHider$AnnotationProcessor”和“lombok.launch.AnnotationProcessorHider$ClaimingProcessor”。在编译类路径上检测注解处理器已被弃用,Gradle 5.0 将忽略它们。请将它们添加到注释处理器路径中。如果您不打算使用注释处理器,则可以使用“-proc:none”编译器参数来忽略它们。

It seems that annotation processors are deprecated and gradle version 5.0 will not support annotation processors.

似乎不推荐使用注释处理器,并且 gradle 5.0 版将不支持注释处理器。

My project uses lombok, which requries annotation processors, so using -proc:noneis not an option. Neither is stopping using Gradle when verison 5.0 is released.

我的项目使用 lombok,它需要注释处理器,因此-proc:none不能选择使用。当版本 5.0 发布时,也不会停止使用 Gradle。

How do I:

我如何能:

  • stop the warnings, and
  • ensure my project will continue to build with future Gradle releases?
  • 停止警告,以及
  • 确保我的项目将继续使用未来的 Gradle 版本构建?

采纳答案by Bohemian

Change the lombok dependency type from compileto annotationProcessor, so your dependencies section in your build.gradlefile should look like:

将 lombok 依赖项类型从 更改compileannotationProcessor,因此build.gradle文件中的依赖项部分应如下所示:

dependencies {
    compileOnly('org.projectlombok:lombok:1.16.20')
    annotationProcessor 'org.projectlombok:lombok:1.16.20'
    // compile 'org.projectlombok:lombok:1.16.20' <-- this no longer works!
    // other dependencies...
}

回答by TecHunter

Gradle added annotationProcessor in 4.6and Lombok is an annotation processor even though their documentation is not really clear about this when using Gradle they are also aware of it as they recommend it when using Android Studio. So short answer is to use:

Gradle 在 4.6 中添加了 annotationProcessor并且 Lombok 是一个注解处理器,尽管他们的文档在使用 Gradle 时对此并不十分清楚,但他们也意识到了这一点,因为他们在使用Android Studio时推荐它。所以简短的回答是使用:

dependencies {
    compileOnly('org.projectlombok:lombok:1.18.0')
    annotationProcessor('org.projectlombok:lombok:1.18.0')
}

回答by Andy Brown

If your project contains tests then you'll need the following configuration to completely rid yourself of the gradle warning:

如果您的项目包含测试,那么您将需要以下配置来完全摆脱 gradle 警告:

dependencies {
  compileOnly "org.projectlombok:lombok:1.18.2"
  testCompileOnly "org.projectlombok:lombok:1.18.2"
  annotationProcessor "org.projectlombok:lombok:1.18.2"
  testAnnotationProcessor "org.projectlombok:lombok:1.18.2"
}

Adjust the lombok version to suit.

调整 lombok 版本以适应。