【发布时间】:2011-02-06 07:50:36
【问题描述】:
主要问题
我想做的事情相当简单。或者你会这么想。但是,没有任何工作正常。
要求: 使用maven,使用AspectJ编译器编译Java 1.6项目。
注意: 我们的代码不能用 javac 编译。也就是说,如果没有编织切面(因为我们有软化异常的切面),它会导致编译失败。
2011 年 2 月 21 日更新: 有两种同样可行的解决方案(两种情况都使用 aspectj-maven-plugin 与 maven-compiler-plugin):
<failOnError>false</failOnError>
到编译器插件(谢谢
Pascal Thivent)<phase>process-sources</phase>
到aspectj编译器插件
(感谢Andrew Swan)关于这些解决方案的更多信息在答案部分。我相信解决方案 #2 是更好的方法。
相关问题
问题(基于以下失败的尝试):
- 如何让 maven 直接运行 aspectj:compile 目标,而无需运行 compile:compile?
- 如何忽略compile:compile的失败?
- 如何指定指向您自己的 ajc 编译器的自定义 compilerId(即 make compile:compile 使用除 plexus 之外的 aspectj 编译器)?*
尝试 1(失败): 指定 aspectJ 作为 maven-compiler-plugin 的编译器:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerId>aspectj</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-aspectj</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
</plugin>
这失败并出现错误:
org.codehaus.plexus.compiler.CompilerException: The source version was not recognized: 1.6
无论我使用什么版本的 plexus 编译器(1.8、1.6、1.3 等),这都不起作用。我其实通读了源码,发现这个编译器不喜欢Java 1.5以上的源码。
尝试 2(失败): 使用附加到 compile 和 test-compile 目标的 aspectJ-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
运行时失败:
mvn clean test-compile
mvn clean compile
因为它会在运行 aspectj:compile 之前尝试执行 compile:compile。如上所述,我们的代码不能用 javac 编译——这些方面是必需的。所以 mvn 需要完全跳过 compile:compile 目标,只运行 aspectj:compile。
尝试 3(有效但不可接受):
使用与上述相同的配置,但改为运行:
mvn clean aspectj:compile
这很有效,因为它可以成功构建,但它是不可接受的,因为我们需要能够直接运行 compile 目标和 test-compile 目标(m2eclipse 自动构建取决于这些目标)。此外,以这种方式运行它需要我们在此过程中阐明我们想要的每一个目标(例如,我们需要分发资源、运行测试和部署测试资源等)
【问题讨论】: