31

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

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.

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

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

How do I:

  • stop the warnings, and
  • ensure my project will continue to build with future Gradle releases?
Bohemian
  • 412,405
  • 93
  • 575
  • 722

3 Answers3

41

Change the lombok dependency type from compile to annotationProcessor, so your dependencies section in your build.gradle file should look like:

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...
}
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • 1
    When I do that, I get: "Could not find method annotationProcssor() for arguments [org.projectlombok:lombok:1.16.20] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler" – JeffH May 22 '18 at 02:02
  • 3
    Yes, for the time being as lombok does not release separate jar files for their API (annotations) and Annotation Processor, you'll have to add the jar file to both the `compile` and the `annotationProcessor` dependency configurations – Ben M Jul 10 '18 at 15:39
  • I get: Could not find method compileOnly() – BriOnH Apr 19 '19 at 18:54
  • @BriOnH what versions of gradle and java are you using? – Bohemian Apr 20 '19 at 00:39
29

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

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.

Andy Brown
  • 11,766
  • 2
  • 42
  • 61
8

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. So short answer is to use:

dependencies {
    compileOnly('org.projectlombok:lombok:1.18.0')
    annotationProcessor('org.projectlombok:lombok:1.18.0')
}
TecHunter
  • 6,091
  • 2
  • 30
  • 47