Maven AspectJ plugin fails to build with Java 9 due to missing tools.jar
Asked Answered
A

4

17

I switched my JDK version from 8 to 9 and the AspectJ plugin no longer works due to missing tools.jar:

Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.10:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.10 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:9.0.1 at specified path C:\Program Files\Java\jdk-9.0.1/../lib/tools.jar

I understand that tools.jar (and rt.jar) were removed from Java 9 JDK. I am wondering if there a way to get Maven AspectJ plugin to work with Java 9 without tools.jar?

Here is my plugin definition with version info:

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>aspectj-maven-plugin</artifactId>
      <version>1.10</version>
      <configuration>       
      <encoding>${project.build.sourceEncoding}</encoding>
      <complianceLevel>1.9</complianceLevel>
      <showWeaveInfo>true</showWeaveInfo>
      <XnoInline>true</XnoInline>         
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>compile</goal>
              <goal>test-compile</goal>
          </goals>
        </execution>
      </executions>     
      <dependencies>
       <dependency>
       <groupId>org.aspectj</groupId>
       <artifactId>aspectjrt</artifactId>
       <version>1.9.0.RC2</version>
      </dependency> 
      <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.9.0.RC2</version>
       </dependency>          
      </dependencies>
    </plugin>
Aleishaalejandra answered 9/1, 2018 at 17:47 Comment(0)
B
13

I just found an ugly trick to make aspectj working with Java 9, just point com.sun:tools to the pom.xml and the compiler just run.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.11</version>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <complianceLevel>1.8</complianceLevel>
                <encoding>UTF-8</encoding>
                <verbose>true</verbose>
                <weaveDependencies>
                    <weaveDependency>
                        <groupId>io.grpc</groupId>
                        <artifactId>grpc-netty</artifactId>
                    </weaveDependency>
                </weaveDependencies>
                <showWeaveInfo>true</showWeaveInfo>
                <XnoInline>true</XnoInline>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>${java.version}</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/pom.xml</systemPath>
        </dependency>
    </dependencies>
</plugin>
Biliary answered 25/3, 2018 at 9:23 Comment(2)
Wow, how did you find that out? It worked for me with JDK 12.Maracanda
Thank you, working with JDK 9. It would be nice, if there will be a support from mojo and we don't need this hack :-)Dorsman
F
11

Until version 1.11.1 is released into Maven Central by org.codehaus.mojo use the snapshot build instead:

<groupId>com.github.m50d</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11.1</version>
Favus answered 11/9, 2018 at 13:27 Comment(1)
@Enerccio actually it was fixed on 2021-05-30, but as of 2021-07-16 the fix was not released yet.Favus
F
3

Ran into the same issue, the problem is that this transitive dependency is active by default in the aspectj-maven-plugin.

Fixed it for me with this PR https://github.com/mojohaus/aspectj-maven-plugin/pull/35

Furor answered 3/2, 2018 at 20:34 Comment(0)
D
-3

Have you checked the newest plugin version?

<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
Danidania answered 18/1, 2018 at 13:55 Comment(2)
Same issue with version 1.11: 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:9.0.4 at specified path C:\Program Files\Java\jdk-9.0.4/../lib/tools.jarAleishaalejandra
@MrkK, see izogfif's answer. That worked for me using Java 10.0.2 having the same problem as you.Goodygoody

© 2022 - 2024 — McMap. All rights reserved.