java 如何让 Lombok 和 AspectJ 协同工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25903686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make Lombok and AspectJ work together?
提问by Eric B.
I just finished posting this issue on SOabout 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.
我刚刚在 SO 上发布了关于 Lombok 没有生成我的 getter/setter 的问题。事实证明,它与 AspectJ 相冲突。如果我禁用 AspectJ,则会适当地生成 getter/setter。
My guess is that the ajc compiler is not able to recognize lombok.
我的猜测是 ajc 编译器无法识别 lombok。
Are Lombok and AspectJ mutually exclusive? Do both technologies work together?
Lombok 和 AspectJ 是互斥的吗?这两种技术可以协同工作吗?
回答by kriegaex
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.
根据 AspectJ 维护者 Andy Clement 的当前答案是,由于在 AspectJ 编译器基础结构中包含并重命名了 ECJ(Java Eclipse 编译器)包,因此存在问题。
For more information there is ongoing discussion between Eric B. and A. Clement on the AspectJ users mailing list:
有关更多信息,Eric B. 和 A. Clement 在 AspectJ 用户邮件列表上正在进行讨论:
Maybe we can close the issue here with this answer and report back when the problem is solved.
也许我们可以用这个答案在这里关闭问题,并在问题解决后报告。
回答by Cheng.T
Add Project Lombok as a dependency to the aspectj-maven-plugin as in:
添加 Project Lombok 作为对 aspectj-maven-plugin 的依赖,如下所示:
<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>