Maven AspectJ插件由于缺少工具而无法使用Java 9构建.jar

我将JDK版本从8切换到9,由于缺少工具,AspectJ插件不再工作.jar:

目标 org.codehaus.mojo:aspectj-maven-plugin:1.10:编译失败的执行默认值:Plugin org.codehaus.mojo:aspectj-maven-plugin:1.10 或其依赖项之一无法解析:在指定的路径 C:\Program Files\Java\jdk-9.0.1/.处找不到 artifact com.sun:tools:jar:9.0.1。/lib/tools.jar

据我所知,工具.jar(和rt.jar)是从Java 9 JDK中删除的。我想知道是否有办法让Maven AspectJ插件在没有工具的情况下与Java 9一起使用.jar?

这是我的插件定义和版本信息:

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

答案 1

我刚刚发现了一个丑陋的技巧,让aspectj使用Java 9,只需将com.sun:tools指向pom.xml编译器就运行了。

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

答案 2

在版本发布到 Maven Central 之前,请改用快照版本1.11.1org.codehaus.mojo

<groupId>com.github.m50d</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11.1</version>

推荐