Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

annotationProcessor gradle 4.7+ configuration doesn't run lombok

Tags:

gradle

lombok

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?

like image 295
coderatchet Avatar asked May 24 '18 22:05

coderatchet


1 Answers

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.

EDIT October 2020:

A Gradle plugin is available by io.freefair that configures these settings and more automatically and helps keep lombok up-to-date (of course you may override the lombok version yourself).

like image 127
coderatchet Avatar answered Nov 03 '22 01:11

coderatchet