aspectj-maven-plugin 和 Java 7

han*_*nsi 5 java plugins aspectj version maven

我必须如何设置 pom.xml 以便 aspectj-maven-plugin 使用 Java 7 进行编译?

当我使用当前配置(见下文)进行编译时,我总是收到一条消息,抱怨我使用了某些 Java 7 特定功能,例如

error: multi-catch statement is not supported in -source 1.5
Run Code Online (Sandbox Code Playgroud)

我使用 eclipse,在项目属性 -> java 编译器中它说 1.5 表示合规性级别、源代码、目标。我究竟做错了什么?

这里提出一个非常相似的问题,但该解决方案对我不起作用,我已经在 org.aspectj 的 1.7.4 版上。

这个问题也可以改写为:

如何让 maven 使用 Java 7 编译我的代码并编织方面?

我不必使用 aspectj-maven-plugin。但是还有什么其他方法有效呢?

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.stuff</groupId>
    <artifactId>artifact</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.7.4</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.5</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

han*_*nsi 3

我在这个问题中找到了一种方法。问题似乎是java和aspectj编译器没有按照人们期望的顺序调用。

简而言之,添加<phase>process-sources</phase>对我来说完成了这项工作:

<executions>
 <execution>
  <phase>process-sources</phase>
  <goals>
   <goal>compile</goal>
   <goal>test-compile</goal>
  </goals>
 </execution>
</executions>
Run Code Online (Sandbox Code Playgroud)