Lombok and AspectJ

NyxMC picture NyxMC · Jan 28, 2017 · Viewed 11.2k times · Source

Im trying to use Lombok in combination with AspectJ and Maven. So, what's the problem? When i use the AspectJ Maven Plugin (www.mojohaus.org/aspectj-maven-plugin/), it takes the sources and compiles them and ignores changes made by Lombok. I followed this tutorial and came up with this code and AspectJ works, but Lombok dies with this message:

[WARNING] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
Lombok supports: sun/apple javac 1.6, ECJ

So, does anyone know how to get Lombok in combination with AspectJ working?

[EDIT] IT WORKS! Now, it seems to work when i package the project to a fat jar. But it still does not work with maven:test and IntelliJ. I'd be happy if anyone had a fix for this.

Best regards!

Answer

SoilChang  picture SoilChang · Oct 18, 2018

Use ajc to process classes.

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.11</version>

            <configuration>
                <complianceLevel>8</complianceLevel>
                <source>8</source>
                <target>8</target>
                <showWeaveInfo>true</showWeaveInfo>
                <verbose>true</verbose>
                <Xlint>ignore</Xlint>
                <encoding>UTF-8</encoding>


                <!-- IMPORTANT-->
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
                <forceAjcCompile>true</forceAjcCompile>
                <sources/>
                <!-- IMPORTANT-->


                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>you.own.aspect.libary</groupId>
                        <artifactId>your-library</artifactId>
                    </aspectLibrary>
                </aspectLibraries>

            </configuration>
            <executions>
                <execution>
                    <id>default-compile</id>
                    <phase>process-classes</phase>
                    <goals>
                        <!-- use this goal to weave all your main classes -->
                        <goal>compile</goal>
                    </goals>
                    <configuration>
                        <weaveDirectories>
                            <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
                        </weaveDirectories>
                    </configuration>
                </execution>
                <execution>
                    <id>default-testCompile</id>
                    <phase>process-test-classes</phase>
                    <goals>
                        <!-- use this goal to weave all your test classes -->
                        <goal>test-compile</goal>
                    </goals>
                    <configuration>
                        <weaveDirectories>
                            <weaveDirectory>${project.build.directory}/test-classes</weaveDirectory>
                        </weaveDirectories>
                    </configuration>
                </execution>
            </executions>
        </plugin>