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

1

7

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.

Towboat answered 5/6, 2020 at 3:57 Comment(0)
V
12

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

Vagary answered 5/6, 2020 at 10:14 Comment(9)
Can you please edit your answer in accordance with your own contribution. Thank you very much for your collaboration and initiative :) com.nickwongdev is out of the game.Servomechanical
Nick's 1.12.6 is still the current release. I have just released a 1.12.7-SNAPSHOT version supporting Java 14-16, not a release yet. I want to wait until AspectJ 1.9.7 is out in order to make AspectJ Maven depend on it. Currently it depends on a 1.9.7-SNAPSHOT, too. But thanks for the reminder.Vagary
aspectj-maven-plugin 1.14.0 is released now and should support newer Java versions.Isolda
Yes, up to Java 16. My fork with group ID dev.aspectj in version 1.13 already supports Java 17 and has more features.Vagary
@Vagary Does aspectj-maven-plugin 1.14.0 (Group :org.codehaus.mojo) supports OpenJDK17 ?Liquate
@Rehman, no, but the dev.aspectj version does. Please note my updated answer.Vagary
Thanks @Vagary for the update. I actually did that yesterday after going through your comments in github. But after doing that I am getting [ERROR] error unrecognized single argument: "-17". error. Any idea about this error ?Liquate
Please don't hijack this question. Please post a new question and provide a full, minimal project called an MCVE. Then I can easily answer your qurestion. I cannot debug what I cannot see.Vagary
@Rehman: FWIW, my guess is that you simply use an AspectJ compiler (AJC) version (contained in org.aspectj:aspectjtools) older than the default 1.9.8.RC1 used in dev.aspectj:aspectj-maven-plugin:1.13.1. Older AJC versions do not support source, target or compliance level 17.Vagary

© 2022 - 2024 — McMap. All rights reserved.