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

发布于 2024-12-03 21:31:19 字数 1865 浏览 2 评论 0原文

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

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

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

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

我有一些依赖项:

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

如何解决此问题?谢谢。

解决方案

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

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

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:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清风疏影 2024-12-10 21:31:19

您可以显式设置aspectj插件的source参数。文档此处

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

雪化雨蝶 2024-12-10 21:31:19

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

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

能够从 这篇文章

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

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

was able to find this from this post.

桜花祭 2024-12-10 21:31:19

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

Check this page and 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文