简体   繁体   English

由于缺少 tools.jar,Maven AspectJ 插件无法使用 Java 9 构建

[英]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:我将我的 JDK 版本从 8 切换到 9,由于缺少 tools.jar,AspectJ 插件不再工作:

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目标 org.codehaus.mojo:aspectj-maven-plugin:1.10:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.10 的执行默认值或其依赖项之一无法解析:Could not find artifact com .sun:tools:jar:9.0.1 在指定路径 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.我知道 tools.jar(和 rt.jar)已从 Java 9 JDK 中删除。 I am wondering if there a way to get Maven AspectJ plugin to work with Java 9 without tools.jar?我想知道是否有办法让 Maven AspectJ 插件在没有 tools.jar 的情况下与 Java 9 一起工作?

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>

Until version 1.11.1 is released into Maven Central by org.codehaus.mojo use the snapshot build instead:org.codehaus.mojo1.11.1版本发布到 Maven Central 之前, org.codehaus.mojo改用快照构建

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

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.我刚刚发现了一个让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>

Ran into the same issue, the problem is that this transitive dependency is active by default in the aspectj-maven-plugin.遇到了同样的问题,问题是这个传递依赖在 aspectj-maven-plugin 中默认是活动的。

Fixed it for me with this PR https://github.com/mojohaus/aspectj-maven-plugin/pull/35用这个 PR 为我修复了它https://github.com/mojohaus/aspectj-maven-plugin/pull/35

Have you checked the newest plugin version?您是否检查过最新的插件版本?

<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM