语法错误,注释仅在源级别为 5.0 时可用 - Maven 中的 AspectJ
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以显式设置aspectj插件的source参数。文档此处。
You can explicity set the source parameter of the aspectj plugin. Docs here.
我能够通过将以下内容添加到我的 pom 中来解决这个问题:
能够从 这篇文章。
I was able to solve this issue by adding the following to my pom:
was able to find this from this post.
检查此页面,我在其中看到一个“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).