I have a root module and submodule in maven in the project. I am trying to use Lombok. I have added
org.projectlombok&
I had this same issue and nothing worked, i.e. maven plugin version, annotationProcessorPaths, provided scope, etc.
In the end I narrowed it down to having a static import on an @UtilityClass
method from a class within the same project, i.e. not brought in from a dependency. This caused annotation processing to fail, even for unrelated classes, and made it look like lombok code was just not being compiled properly. Getting rid of the static import made it all work.
There's an open issue on Github for this, though apparently it's too hard to fix.
I'm not sure what the difference is between lombok and lombok-maven-plugin, but my projects are configured with this dependency:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.12.0</version>
</dependency>
I haven't experimented with root and submodule poms yet, as my projects all tend to be rather isolated from each other. Not sure if that could be causing an issue for you.
If you are using Eclipse, have you run the lombok.jar file and pointed it to your eclipse.exe file? it needs to modify the .exe in order for Eclipse to know that those getters and setters are coming, so that Eclipse doesn't complain during development.
Edit: I'm using maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Maven Groovy and Java + Lombok
The solution on this stack overflow answer worked for me. I missed adding the javaAgentClass earlier
In case of anyone using JDK 11
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-sourcepath</arg>
<arg>${project.basedir}/src/main/java${path.separator}${project.basedir}/target/generated-sources/annotations${path.separator}/</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
I was using Java 8 and @Getter(onMethod = @__({@NoSerialization}))
and @Getter(onMethod = @__({@Translation(messageKey = "translation.key")}))
onX annotations. And I get duplicate element '<any?>' in annotation @<any?>.
in error output. Looks like guys from Lombok have such issue with Java 8 for a long time link to issue on github. Lombok does not handle annotations with parameters like messageKey
in annotation above. it works only with annotations without parameters and annotations with only value
parameter (when you don't write the name of parameter).
use:
<scope>provided</scope>
in pom.xml like that:
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
<scope>provided</scope>
</dependency>
</dependencies>