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

Gradle deprecated annotation processor warnings for lombok

升级到 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.

注释处理器似乎已被弃用,gradle 5.0 版将不支持注释处理器。

我的项目使用 lombok,它需要注释处理器,所以使用 -proc:none 不是一个选项。当版本 5.0 发布时,也不会停止使用 Gradle。

我如何:

将 lombok 依赖类型从 compile 更改为 annotationProcessor,因此 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...
}

Gradle added annotationProcessor in 4.6 and 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。 简短的回答是使用:

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

如果您的项目包含测试,那么您将需要以下配置来完全摆脱 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"
}

调整 lombok 版本以适应。