我将JDK版本从8改为9,AspectJ插件由于缺少tools.jar而不再工作:
目标org.codehaus.mojo:aspectj-maven-plugin:1.10:compile的默认执行失败:pluginorg.codehaus.mojo:aspectj Plugin :1.10或其依赖项之一无法解决:无法在指定路径C:\Program \Java\JDK-9.0.1/lib/tools.jar中找到工件com.sun:tools:jar:9.0.1
我知道tools.jar (和rt.jar)已经从Java9JDK中删除了。我想知道是否有一种方法可以让Maven AspectJ插件在没有tools.jar的情况下使用Java9?
下面是我使用版本信息的插件定义:
<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>发布于 2018-03-25 09:23:12
我刚刚发现了一个让aspectj使用Java9的丑陋技巧,只需将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>发布于 2018-09-11 13:27:34
在1.11.1版本由org.codehaus.mojo发布到Maven Central之前,请使用快照生成:
<groupId>com.github.m50d</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11.1</version>发布于 2018-02-03 20:34:31
遇到同样的问题时,问题是在aspectj plugin中,这种传递依赖在默认情况下是活动的。
用这个PR https://github.com/mojohaus/aspectj-maven-plugin/pull/35帮我修好了
https://stackoverflow.com/questions/48173963
复制相似问题