Is there any way (and any sense) to use Lombok when I am using javapoet?
Here is example:
TypeSpec typeSpec = TypeSpec
.classBuilder("MyDtoWithLombok")
.addModifiers(Modifier.PUBLIC)
//.addAnnotation(NoArgsConstructor.class)
//.addAnnotation(AllArgsConstructor.class)
//.addAnnotation(Data.class)
//.addAnnotation(Builder.class)
.addField(...)
.build();
When I am trying to add Lombok annotation (like that -> Data.class") I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: lombok/NoArgsConstructor
...
Caused by: java.lang.ClassNotFoundException: lombok.NoArgsConstructor
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 3 more
Probably because Lombok is usually given provided scope - you ordinarily don't want it on the classpath, because it's supposed to be processed and removed at compile-time.
Remove the
<scope>provided</scope>line, or change it tocompile. Both are equivalent, sincecompileis the default.I would personally explicitly use
compileand maybe even add a comment explaining why you're not usingprovided, since a casual reader might think it's a mistake otherwise, and maybe try to change it toprovidedagain.