How do you configure aspectj maven plugin to use Java 7?

柔情痞子 提交于 2019-11-29 19:17:37

问题


What are the appropriate configuration/versions/plugin versions for the aspectj plugin to use Java 7?

I am trying to upgrade from Java 6 to Java 7, and the aspectj compiler seems to not be compiling Java 7. I'm specifying the java source and target version as 1.7 in the plugin configuration for aspectj plugin and for the maven compiler plugin. I introduced Java7-specific syntax to my code, adding several language features such as string in switch and the diamond operator. During the build, I get errors from aspectj about the Java7 syntax. The first sign that things are going wrong is:

[INFO] --- aspectj-maven-plugin:1.4:compile (default) @ site ---
[ERROR] Cannot switch on a value of type String. Only int values or enum constants are permitted
[ERROR] Cannot instantiate the type HashSet<?>
[ERROR] Syntax error on token "<", ? expected after this token

If I remove the executions section from the aspectj maven plugin so it doesn't run, and use mvn clean install, the new code compiles fine. So I think it's something misconfigured with aspectj. Here is my plugin configuration:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java-version>1.7</java-version>
    <org.aspectj-version>1.6.11</org.aspectj-version>
</properties>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.4</version>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjrt</artifactId>
                    <version>${org.aspectj-version}</version>
                </dependency>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjtools</artifactId>
                    <version>${org.aspectj-version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <complianceLevel>${java-version}</complianceLevel>
                <encoding>${project.build.sourceEncoding}</encoding>
                <outxml>true</outxml>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>

Also aspectjrt is defined as a dependency outside of the plugins section

<dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${org.aspectj-version}</version>
    </dependency>
<dependencies>

回答1:


I updated from 1.6.11 to 1.7.0, which has been released since I asked this question. I no longer have any aspectj/Java1.7 issues, so that resolves this question.



来源:https://stackoverflow.com/questions/11308447/how-do-you-configure-aspectj-maven-plugin-to-use-java-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!