Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 712
starboost Avatar asked Jun 05 '20 03:06

starboost


1 Answers

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

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

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

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>

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

like image 63
kriegaex Avatar answered Nov 17 '22 11:11

kriegaex