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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7361231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:39:35  来源:igfitidea点击:

Syntax error, annotations are only available if source level is 5.0 - AspectJ in Maven

javaannotationsaspectj

提问by Jér?me Verstrynge

I am trying to use the aspectj-maven-pluginin a maven project. At compile time, I get:

我正在尝试aspectj-maven-plugin在 Maven 项目中使用 。在编译时,我得到:

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

Yet, I set the following in my pom.xml:

然而,我在 pom.xml 中设置了以下内容:

<project.build.source>1.6</project.build.source>
<project.build.target>1.6</project.build.target>

I have some dependencies to:

我有一些依赖:

    <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>

How do I solve this issue? Thanks.

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

Solution

解决方案

I added the following in my pom.xml and now it works:

我在我的 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>

采纳答案by Paul Grime

You can explicity set the source parameter of the aspectj plugin. Docs here.

您可以显式设置 aspectj 插件的 source 参数。文档在这里

回答by Gabriel Dimech

I was able to solve this issue by adding the following to my pom:

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

<properties>
<project.build.java.target>1.6</project.build.java.target>
</properties>

was able to find this from thispost.

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

回答by Yhn

Check this pageand I see a "complianceLevel" configuration property in that example; setting that to 1.5 or 1.6 might do the trick (since they have a minimum of 1.4, I'm guessing that's the default).

检查此页面,我在该示例中看到“complianceLevel”配置属性;将其设置为 1.5 或 1.6 可能会奏效(因为它们的最小值为 1.4,我猜这是默认值)。