问题
I just finished posting this issue on SO about Lombok not generating my getters/setters. It turns out that it is conflicting with AspectJ. If I disable AspectJ, then the getters/setters are appropriately generated.
My guess is that the ajc compiler is not able to recognize lombok.
Are Lombok and AspectJ mutually exclusive? Do both technologies work together?
回答1:
The current answer according to AspectJ maintainer Andy Clement is that there are problems due to ECJ (Eclipse Compiler for Java) packages being included and renamed in the AspectJ compiler infrastructure.
For more information there is ongoing discussion between Eric B. and A. Clement on the AspectJ users mailing list:
- Discussion thread
- Discussion thread continued
Maybe we can close the issue here with this answer and report back when the problem is solved.
回答2:
Add Project Lombok as a dependency to the aspectj-maven-plugin as in:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>compile</scope>
</dependency>
For example:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>compile</scope>
</dependency>
</dependencies>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<complianceLevel>${java.version}</complianceLevel>
<encoding>${project.build.sourceEncoding}</encoding>
<verbose>true</verbose>
<privateScope>true</privateScope>
<showWeaveInfo>true</showWeaveInfo>
<outxml>true</outxml>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
<configuration>
<aspectLibraries combine.self="override">
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
</execution>
</executions>
</plugin>
来源:https://stackoverflow.com/questions/25903686/how-to-make-lombok-and-aspectj-work-together