如何让Lombok和AspectJ协同工作?

问题描述 投票:0回答:3

我刚刚在SO上发布了这个问题,关于Lombok没有生成我的getter/setter。原来是和AspectJ冲突了。如果我禁用 AspectJ,则会正确生成 getter/setter。

我的猜测是ajc编译器无法识别lombok。

Lombok 和 AspectJ 是互斥的吗?这两种技术可以一起工作吗?

java aspectj lombok
3个回答
9
投票

AspectJ 维护者 Andy Clement 给出的当前答案是,由于 ECJ(Eclipse Compiler for Java)包被包含在 AspectJ 编译器基础结构中并被重命名,因此存在问题。

有关更多信息,Eric B. 和 A. Clement 正在 AspectJ 用户邮件列表上进行讨论:

也许我们可以用这个答案来关闭这个问题,并在问题解决后报告。


0
投票

2022 年 - AWS 文档中的 Lambda Powertools 常见问题解答对此有答案:https://awslabs.github.io/aws-lambda-powertools-java/FAQs/

要启用就地编织功能,您需要使用以下aspectj-maven-plugin配置:

<configuration>
    <forceAjcCompile>true</forceAjcCompile> 
    <sources/>
    <weaveDirectories>
        <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
    </weaveDirectories>
    ...
    <aspectLibraries>
        <aspectLibrary>
            <groupId>software.amazon.lambda</groupId>
            <artifactId>powertools-logging</artifactId>
        </aspectLibrary>
    </aspectLibraries>
</configuration>

-2
投票

将 Lombok 项目添加为aspectj-maven-plugin 的依赖项,如下所示:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.18</version>
    <scope>compile</scope>
</dependency>

例如:

<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>
© www.soinside.com 2019 - 2024. All rights reserved.