Yar*_*iev 1 java aspectj maven aspectj-maven-plugin
当我使用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>
Run Code Online (Sandbox Code Playgroud)
是的,您可以停用 Maven 编译器插件,因为 AspectJ 编译器是 Eclipse Java 编译器的定期刷新分支。因此,它也可以编译你的Java文件。
但如果情况比较复杂,例如你使用Maven Compiler还编译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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5230 次 |
| 最近记录: |