如何配置Aspectj Maven插件以使用Java 7? [英] How do you configure aspectj maven plugin to use Java 7?

查看:95
本文介绍了如何配置Aspectj Maven插件以使用Java 7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

供Aspectj插件使用Java 7的适当配置/版本/插件版本是什么?

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

我正在尝试从Java 6升级到Java 7,而AspectJ编译器似乎未在编译Java7.我在AspectJ插件和Maven的插件配置中将Java源版本和目标版本指定为1.7.编译器插件.我在代码中引入了Java7特定的语法,并添加了一些语言功能,例如switch中的字符串和菱形运算符.在构建过程中,我从Aspectj中收到有关Java7语法的错误.出现问题的第一个迹象是:

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

如果我从Aspectj Maven插件中删除了executes部分,使其无法运行,并使用mvn clean install,则新代码可以正常编译.所以我认为这是AspectJ配置错误的内容.这是我的插件配置:

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>

aspectjrt也定义为插件部分之外的依赖项

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.6.11更新到1.7.0,该问题是自我提出此问题以来发布的.我不再有aspectj/Java1.7问题,因此可以解决此问题.

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.

这篇关于如何配置Aspectj Maven插件以使用Java 7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆