语法错误,注释仅在源级别为5.0时才可用 - Maven中的AspectJ

Jér*_*nge 15 java annotations aspectj

我正在尝试使用aspectj-maven-pluginmaven项目.在编译时,我得到:

Syntax error, annotations are only available if source level is 5.0
Syntax error, annotations are only available if source level is 5.0
Syntax error, annotations are only available if source level is 5.0
Run Code Online (Sandbox Code Playgroud)

但是,我在我的pom.xml中设置了以下内容:

<project.build.source>1.6</project.build.source>
<project.build.target>1.6</project.build.target>
Run Code Online (Sandbox Code Playgroud)

我有一些依赖:

    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.6.11</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.4</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?谢谢.

我在我的pom.xml中添加了以下内容,现在它可以工作:

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

Pau*_*ime 8

您可以明确设置aspectj插件的source参数.文档在这里.


小智 5

通过在我的pom中添加以下内容,我能够解决这个问题:

<properties>
<project.build.java.target>1.6</project.build.java.target>
</properties>
Run Code Online (Sandbox Code Playgroud)

能够从这篇文章中找到这个.