Does Mojo's AspectJ Maven Plugin work with jdk 9+?

夙愿已清 提交于 2020-08-25 06:59:39

问题


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

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>

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


回答1:


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>

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.: There is not need to provide hard-coded paths, just use the alternative plugin. :-)



来源:https://stackoverflow.com/questions/62207894/does-mojos-aspectj-maven-plugin-work-with-jdk-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!