当我使用 maven-apsectj-plugin
和 maven-compiler-plugin
compile
阶段将执行这两个插件 compile
目标。
这会导致首先使用 javac
进行编译,然后使用 ajc
进行完全重新编译。
这个双重编译有必要吗?看来我只需关闭 maven-compiler-plugin
即可,一切正常。
我正在使用“默认”配置,如 maven-compiler-plugin
的使用中所述:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.13</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<executions>
<execution>
<goals>
<goal>compile</goal> <!-- use this goal to weave all your main classes -->
<goal>test-compile</goal> <!-- use this goal to weave all your test classes -->
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
<build>
...
</project>
最佳答案
是的,您可以停用 Maven 编译器插件,因为 AspectJ 编译器是 Eclipse Java 编译器的定期刷新分支。因此,它也可以编译您的Java文件。
但如果情况比较复杂,例如您使用 Maven 编译器还编译 Groovy 文件或其他模块中的文件,并且只想在 <pluginManagement>
中配置一次,也许停用它不是一个好的选择。有一种方法可以让两个插件很好地协同工作,请参阅我的其他答案
基本上,您将 Maven 编译器配置为使用 <useIncrementalCompilation>false</useIncrementalCompilation>
和 AspectJ Maven 使用 <phase>process-sources</phase>
。更多信息位于链接的答案中。
然后你会看到这样的输出:
[INFO] --- aspectj-maven-plugin:1.12.1:compile (default) @ openbook_cleaner ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[INFO]
[INFO] --- aspectj-maven-plugin:1.12.1:test-compile (default) @ openbook_cleaner ---
[WARNING] No sources found skipping aspectJ compile
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ openbook_cleaner ---
[INFO] Nothing to compile - all classes are up to date
关于java - 使用maven-compiler-plugin和aspectj-maven-plugin进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56942234/