我进行了广泛搜索,但没有找到任何可以帮助我解决问题的方法。我正在尝试实现某个功能并且我正在创建一个 PoC 解决方案,但这是一个问题:
它涉及使用编译时编织的 AspectJ 和编译时注释处理器
而且我不知道如何使这两者同时工作。
到目前为止,我一直在 *.aj 文件中使用 aspectj-maven-plugin 中的 AspectJ 方面,它工作正常。但是,当我尝试使用 maven-compiler-plugin 添加注释处理时,一个问题变得明显:在编译阶段由 aspectj-maven-plugin 生成的目标目录中的编织类被 maven-compiler-plugin 覆盖通过它在编译阶段生成的类。
控制台输出说,首先 aspectj-maven-plugin 完成了它的工作并编织了所有类:
[INFO] --- aspectj-maven-plugin:1.10:compile (default) @ demo ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
...and a list of all the Join Points and Intertypes done
但随后 maven-compiler-plugin 开始工作并重新编译所有内容(并使用注释处理器生成类):
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to dir\demo\target\classes
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (compile-project) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 19 source files to dir\demo\target\classes
这是 pom.xml 的相关部分:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<compilerArgument>-proc:none</compilerArgument>
<includes>
<include>
path/to/annotation/processor/Processor.java
</include>
</includes>
</configuration>
</execution>
<execution>
<id>compile-project</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.10</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<complianceLevel>${maven.compiler.source}</complianceLevel>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
另外,方面和注释处理器都工作正常,所以它们特别不是问题,我认为问题是构建配置。
我猜要么我把插件中的执行/阶段搞砸了,要么我什至不需要同时使用它们,也许只有一个正确配置就足够了,但我不知道如何将编译与 ajc 结合并运行注释处理器(分两个阶段,首先使用 proc none 编译注释处理器本身,然后进行注释处理)。请帮忙!