Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 931
MrkK Avatar asked Jan 09 '18 17:01

MrkK


2 Answers

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>
like image 167
izogfif Avatar answered Sep 22 '22 13:09

izogfif


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>
like image 44
James Pan Avatar answered Sep 22 '22 13:09

James Pan