龙目岛和AspectJ

2022-09-01 14:38:58

我试图将龙目岛与AspectJ和Maven结合使用。那么,问题出在哪里呢?当我使用AspectJ Maven插件(www.mojohaus.org/aspectj-maven-plugin/)时,它会获取源代码并编译它们并忽略龙目岛所做的更改。我按照本教程并提出了这个代码,AspectJ工作,但龙目岛死了这个消息:

[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

那么,有谁知道如何让龙目岛与AspectJ结合使用?

[编辑]它的工作原理!现在,当我将项目打包到一个胖罐子中时,它似乎可以工作。但它仍然不适用于maven:test和IntelliJ。如果有人对此有解决方案,我会很高兴。

此致敬意!


答案 1

使用 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>

答案 2

使用 delombok 生成正常的源代码。然后,如果没有使用龙目岛,请继续操作。

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


推荐