当我使用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>
答案 0 :(得分:1)
是的,您可以停用Maven Compiler插件,因为AspectJ编译器是Eclipse Java Compiler的定期刷新分支。因此也可以编译您的Java文件。
但是,如果情况更为复杂,例如您使用Maven编译器还编译了Groovy文件或其他模块中的文件,并且只想在<pluginManagement>
中对其进行一次配置,也许停用它不是一个好选择。有一种方法可以使两个插件配合使用,请参阅我的其他答案
基本上,您将Maven Compiler配置为使用<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