Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lombok and AspectJ

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!

like image 714
NyxMC Avatar asked Jan 28 '17 12:01

NyxMC


People also ask

What is AspectJ Maven plugin used for?

Maven AspectJ Plug-inIt offers the ability to weave aspects on the classes generated and dependency libraries. This also includes the ability to add dependencies on libraries with aspects.

What is Delombok?

Delombok's standard mode of operation is that it copies an entire directory into another directory, recursively, skipping class files, and applying lombok transformations to any java source files it encounters. Delombok's output format can be configured with command line options (use --format-help for a complete list).


2 Answers

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> 
like image 179
SoilChang Avatar answered Sep 21 '22 09:09

SoilChang


Use delombok to generate normal source code. And then proceed as you would if Lombok were not being used.

Store your Lombok-annotated code in main/src/lombok (for example) and then have the delombok plugin convert these annotations into normal code and into the directory /delomboked (for example).

like image 39
Alok P Avatar answered Sep 20 '22 09:09

Alok P