kaps/Maven insists on picking up the Lombok annotation processor

I encountered a problem when using kaps in a Maven project, which has dependencies on MapStruct and Lombok.

Maven/Java versions:

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: /usr/local/dev/apache-maven
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/local/jdk1.8.0_181/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-54-generic", arch: "amd64", family: "unix"

I could reproduce this problem by modifying the pom.xml from this MapStruct example project.

This is the modified pom.xml:

pom.xml (5.6 KB)

The changes in short:

  1. Updated Kotlin version to 1.3.41 in order to make sure to run with a recent one
  2. Added a compile dependency on Lombok
  3. Added <kapt.include.compile.classpath>false</kapt.include.compile.classpath>

I see the following stacktrace:

[WARNING] /home/clemens/projects/mapstruct-examples/mapstruct-kotlin/target/kaptStubs/compile/error/NonExistentClass.java:3: warning: Can’t initialize javac processor due to (most likely) a class loader problem: java.lang.NoClassDefFoundError: com/sun/tools/javac/processing/JavacProcessingEnvironment
public final class NonExistentClass {
^
at lombok.javac.apt.LombokProcessor.getJavacProcessingEnvironment(LombokProcessor.java:410)
at lombok.javac.apt.LombokProcessor.init(LombokProcessor.java:90)
at lombok.core.AnnotationProcessor$JavacDescriptor.want(AnnotationProcessor.java:124)
at lombok.core.AnnotationProcessor.init(AnnotationProcessor.java:177)
at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.init(AnnotationProcessor.java:73)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.init(incrementalProcessors.kt:28)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.init(annotationProcessing.kt:141)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.(JavacProcessingEnvironment.java:500)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:597)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:690)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)
[…]

I see two levels of not understood behaviour:

  1. Why is the Lombok annotation processor applied? It is not listed in <annotationProcessorPaths/>, and I have set <kapt.include.compile.classpath>false</kapt.include.compile.classpath>
  2. Although I would think, that the Lombok annotation processor should not be applied at all, still the fact, that this application results in the above error, exists.

By the way – maybe you are wondering about this strange mixture. Actually, I want to migrate a Java project to Kotlin incrementally, while keeping it productive. The place I want to start are the DTOs, i.e., they are to be migrated to Kotlin data classes.

Thus, in the long run, I won’t use Lombok anymore. With MapStruct I am going to stick.

kapt.include.compile.classpath option is only available in Gradle, see the related issues:
https://youtrack.jetbrains.com/issue/KT-24368
https://youtrack.jetbrains.com/issue/KT-24530

AFAIK there is no workaround for Maven yet. I filed a new issue https://youtrack.jetbrains.com/issue/KT-32743, please follow it for updates.

Thanks a lot, Alexey, that’s good to hear – I will keep track of the updates.