Mojo 的 AspectJ Maven 插件是否适用于 jdk 9+? [英] Does Mojo's AspectJ Maven Plugin work with jdk 9+?

查看:51
本文介绍了Mojo 的 AspectJ Maven 插件是否适用于 jdk 9+?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Mojo 的 AspectJ Maven 插件的项目.它适用于 jdk 8.当我尝试切换到 jdk14 时,构建失败并显示以下错误:

I have a project that uses Mojo's AspectJ Maven Plugin. It works fine with jdk 8. When I try to switch to jdk14, the build fails with the following error:

[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.11:compile (default) on project AspectJDemo: Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.11:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.11 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:13.0.2 at specified path /usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home/../lib/tools.jar -> [Help 1]

Mojo 的网站 确认此文件是必需的依赖项.但是,根据 this自 jdk 9 以来,tools.jar 已被删除.我试图提供一个在我的依赖项中,这个 jar 文件的硬编码路径如下:

Mojo's website confirms that this file is a required dependency. However, according to this tools.jar has been removed since jdk 9. I have tried to provide a hardcoded path to this jar file in my dependencies like this:

        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.8</version>
            <scope>system</scope>
            <systemPath>/path/to/tools.jar</systemPath>
        </dependency>

但是随后构建完全失败,就好像它完全停止识别 Java 一样.我收到许多错误,例如:

But then the build completely fails as if it stops recognizing Java entirely. I get numerous errors such as:

[ERROR] can't find critical required type java.lang.Object
        <unknown source file>:<no line information>

这是否意味着 Mojo 的 AspectJ Maven 插件不支持 jdk9+?对我如何解决此问题的任何想法表示赞赏.

Does this mean Mojo's AspectJ Maven Plugin does not support jdk9+? Any idea on how I could resolve this is appreciated.

推荐答案

2021-10-26 更新: 因为有人在评论中提问,简要概述现状:

Update 2021-10-26: Because someone asked in a comment, a short overview of the status quo:

  • 作为 AspectJ 的共同维护者,我也在维护 AspectJ.dev AspectJ Maven Plugin,因为 Nick 的版本不再维护.当前版本 dev.aspectj:aspectj-maven-plugin:1.13.1 支持 Java 17,默认使用 AspectJ 1.9.8.RC1,它也完全支持 Java 17.它比其他版本有更多的功能上游和分叉变体,是我推荐的变体.它还可以解析大于 17 的版本号,也就是说,将来您可以简单地升级 AspectJ 插件依赖项并提高 Java 合规性级别,而无需像这样升级插件版本,除非您需要新的插件功能.

  • I as a co-maintainer of AspectJ proper am also maintaining the AspectJ.dev AspectJ Maven Plugin, because Nick's version is no longer maintained. The current version dev.aspectj:aspectj-maven-plugin:1.13.1 supports Java 17 and by default uses AspectJ 1.9.8.RC1 which also fully supports Java 17. It has more features than the other upstream and forked variants and is the variant I recommend. It can also parse version numbers greater than 17, i.e. in the future you can simply upgrade the AspectJ plugin dependency and increase the Java compliance level without having to upgrade the plugin version as such, unless you need new plugin features.

最近 Mojohaus 也有一些活动,主要是因为我问他们是否可以宣布他们的插件已弃用,因为在 3.5 年内没有发布并且支持问题和 PR 被忽略了很长时间.当他们注意到我发布了我自己的版本时,因为作为 AspectJ 贡献者,我担心 Maven 用户已经被孤立了这么长时间,他们合并了我的一些(不是全部)更改并发布了 1.14.0 版本,该版本支持Java 16,但不是 Java 17.

Lately there also was some activity at Mojohaus, mostly because I asked them if they could declare their plugin as deprecated, as there was no release in 3.5 years and support questions and PRs were being ignored for a long time. When they noticed that I published my own version, because as an AspectJ contributor I was concerned that Maven users had been left alone for such a long time, they merged in some (not all) of my changes and released version 1.14.0 which supports Java 16, but not Java 17.

话虽如此,我推荐这个插件:

Having said that, I recommend this plugin:

<dependency>
    <groupId>dev.aspectj</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.13.1</version>
</dependency>


此答案的先前版本(现已过时):该插件自 Java 8 起未维护,但有一个 fork 带有 pull request 被上游接受.因为 Mojohaus 没有插件的活跃维护者,并且分支的开发者还没有被授予接管和推出上游版本的访问权限,现在只需使用这个分支:


Previous version of this answer (now obsolete): The plugin has not been maintained since Java 8, but there is a fork with a pull request to be accepted up-stream. Because Mojohaus has no active maintainer for the plugin and the fork's developer has not been granted access rights to take over and push out an upstream release yet, for now just use this fork:

<dependency>
    <groupId>com.nickwongdev</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.12.6</version>
</dependency>

我已经使用它很长时间了,它是可靠的并且至少可以运行到 Java 13.即使是最新版本的 IntelliJ IDEA 也会自动将其识别为 Mojohaus 版本的替代品,因为这个过程已经花费了很长时间.

I have used it for a long time, it is reliable and works at least up to Java 13. Even the latest version of IntelliJ IDEA automatically recognises it as an alternative to the Mojohaus version because this process has taken so long already.

P.S.:无需提供硬编码路径,只需使用替代插件即可.:-)

P.S.: There is not need to provide hard-coded paths, just use the alternative plugin. :-)

这篇关于Mojo 的 AspectJ Maven 插件是否适用于 jdk 9+?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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