annotationProcessor gradle 4.7+ 配置没有 运行 lombok
annotationProcessor gradle 4.7+ configuration doesn't run 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.
当运行
gradlew build --warning-mode=all
在具有以下 Gradle 配置的项目上
compileOnly('org.projectlombok:lombok')
testCompileOnly('org.projectlombok:lombok')
如警告所示,建议将它们放在 annotationProcessor
(和 testAnnotationProcessor
)配置上,以便与 gradle 5.0
兼容
annotationProcessor('org.projectlombok:lombok')
testAnnotationProcessor('org.projectlombok:lombok')
但是,通过简单的测试:
@Slf4j
public class LombokTests {
@Test
public void lombokCompiles() {
log.info("foobar");
}
}
配置失败:
> Task :compileTestJava FAILED
D:\Users\bobjones\repos\my-new-app\src\test\java\com\example\app\LombokTests.java:10: error: cannot find symbol
@Slf4j
^
symbol: class Slf4j
1 error
我是不是漏掉了什么?
添加compileOnly
/testCompileOnly
配置
annotationProcessor('org.projectlombok:lombok')
compileOnly('org.projectlombok:lombok')
testAnnotationProcessor('org.projectlombok:lombok')
testCompileOnly('org.projectlombok:lombok')
根据 documentation,annotationProcessor 配置仍然需要 compileOnly
(和 testCompileOnly
用于测试 类)配置才能运行。至于对增量注释处理的支持,Lombok 的实现者刚刚合并支持 master 但截至 2018 年 5 月 25 日还没有包括上线版本。
他们的最后一个版本 16.2.20 跨越提交直到 9th of Jan 2018 and the Gradle change was pulled into master on the 15th of May 2018 So I suspect the new version won't be far from release, although their 'Edgy' 版本不包含关于此功能的任何注释。
编辑 2020 年 10 月:
一个 Gradle plugin is available by io.freefair 配置这些设置并更自动地帮助保持 lombok 最新(当然你可以自己覆盖 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.
当运行
gradlew build --warning-mode=all
在具有以下 Gradle 配置的项目上
compileOnly('org.projectlombok:lombok')
testCompileOnly('org.projectlombok:lombok')
如警告所示,建议将它们放在 annotationProcessor
(和 testAnnotationProcessor
)配置上,以便与 gradle 5.0
annotationProcessor('org.projectlombok:lombok')
testAnnotationProcessor('org.projectlombok:lombok')
但是,通过简单的测试:
@Slf4j
public class LombokTests {
@Test
public void lombokCompiles() {
log.info("foobar");
}
}
配置失败:
> Task :compileTestJava FAILED
D:\Users\bobjones\repos\my-new-app\src\test\java\com\example\app\LombokTests.java:10: error: cannot find symbol
@Slf4j
^
symbol: class Slf4j
1 error
我是不是漏掉了什么?
添加compileOnly
/testCompileOnly
配置
annotationProcessor('org.projectlombok:lombok')
compileOnly('org.projectlombok:lombok')
testAnnotationProcessor('org.projectlombok:lombok')
testCompileOnly('org.projectlombok:lombok')
根据 documentation,annotationProcessor 配置仍然需要 compileOnly
(和 testCompileOnly
用于测试 类)配置才能运行。至于对增量注释处理的支持,Lombok 的实现者刚刚合并支持 master 但截至 2018 年 5 月 25 日还没有包括上线版本。
他们的最后一个版本 16.2.20 跨越提交直到 9th of Jan 2018 and the Gradle change was pulled into master on the 15th of May 2018 So I suspect the new version won't be far from release, although their 'Edgy' 版本不包含关于此功能的任何注释。
编辑 2020 年 10 月:
一个 Gradle plugin is available by io.freefair 配置这些设置并更自动地帮助保持 lombok 最新(当然你可以自己覆盖 lombok 版本)。