annotationProcessor gradle 4.7+ configuration doesn't run lombok

廉价感情. 提交于 2019-12-22 05:28:18

问题


I have received the following message when working with a gradle 4.7 project

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.

when running

gradlew build --warning-mode=all

on a project with the following Gradle configuration

compileOnly('org.projectlombok:lombok')
testCompileOnly('org.projectlombok:lombok')

As the warning suggests, it is recommended to place these on the annotationProcessor (and testAnnotationProcessor) configurations in order to be compatible with gradle 5.0

annotationProcessor('org.projectlombok:lombok')
testAnnotationProcessor('org.projectlombok:lombok')

However, with a simple test:

@Slf4j
public class LombokTests {
    @Test
    public void lombokCompiles() {
        log.info("foobar");
    }
}

That configuration fails:

> 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

Am I missing something?


回答1:


Add the compileOnly/testCompileOnly configuration

annotationProcessor('org.projectlombok:lombok')
compileOnly('org.projectlombok:lombok')
testAnnotationProcessor('org.projectlombok:lombok')
testCompileOnly('org.projectlombok:lombok')

According to the documentation, the annotationProcessor config still requires the compileOnly (and testCompileOnly for test classes) configuration to function. As for support for incremental annotation processing, the implementers of Lombok have just merged in support to master but as of 25th May 2018 have not included a go-live version.

Their last version 16.2.20 spanning commits up until the 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' release does not include any notes regarding this feature.



来源:https://stackoverflow.com/questions/50519138/annotationprocessor-gradle-4-7-configuration-doesnt-run-lombok

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!