龙目岛和AspectJ

Nyx*_*xMC 12 java aspectj maven lombok

我试图将Lombok与AspectJ和Maven结合使用.所以有什么问题?当我使用AspectJ Maven插件(www.mojohaus.org/aspectj-maven-plugin/)时,它会获取源代码并编译它们并忽略Lombok所做的更改.我按照本教程编写这个代码,AspectJ可以正常工作,但Lombok因此消息而死:

[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
Run Code Online (Sandbox Code Playgroud)

那么,有没有人知道如何让Lombok与AspectJ结合使用?

[编辑]它工作!现在,当我将项目打包到一个胖罐子时似乎工作.但它仍然无法与maven:test和IntelliJ一起使用.如果有人对此有所帮助,我会很高兴.

最好的祝福!

小智 7

使用ajc处理类。

<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>
Run Code Online (Sandbox Code Playgroud)

  • @Ghilteras 我实际上找到了另一个解决方案,而无需切换到 javac。假设您也在使用 Intellij。转到文件 &gt; 项目结构 &gt; 模块 &gt; AspectJ,选中选项:Post-compile weave mode。它应该可以正常工作。 (3认同)
  • 大多数人都知道“${project.build.directory}”是“target”,但是您可以使用“${project.build.outputDirectory}”和“${project.build.testOutputDirectory}”作为“target/classes”, `目标/测试类`:) (3认同)

use*_*736 4

使用delombok生成正常的源代码。然后按照未使用 Lombok 时的方式继续操作。

将带有 Lombok 注释的代码存储在 main/src/lombok 中(例如),然后让 delombok 插件将这些注释转换为普通代码并放入目录 /delomboked(例如)。