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:
- Updated Kotlin version to 1.3.41 in order to make sure to run with a recent one
- Added a compile dependency on Lombok
- 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:
- 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>
- 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.