HOWTO: Maven, Lombok and AspectJ together
2011. 12. 03.If you’re on this page, you have your purpose, you want to configure the maven pom.xml to enable the usage of lombok and aspectj the same time. The solution is to forbid for the aspectj-maven-plugin to regenerate the class files, because without any configuration the compile-and-weaving process looks that way:
- javac compiles your .java files to .class files with lombok (generating methods, etc.)
- aspectj regenerates your classes from the .java files without lombok
So we need to use the in-place weaving feature of the aspectj plugin:
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.12</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.12</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<showWeaveInfo/>
<forceAjcCompile>true</forceAjcCompile>
<sources/>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<aspectLibraries>
...
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
The key of the solution is the empty sources tag in the configuration and the forceAjcCompile=true setting.
Enjoy.