我将JDK版本从8切换到9,由于缺少工具,AspectJ插件不再有效.jar:
目标org.codehaus.mojo的执行默认值:aspectj-maven-plugin:1.10:编译失败:插件org.codehaus.mojo:aspectj-maven-plugin:1.10或其中一个依赖项无法解析:找不到工件com.sun:工具:jar:9.0.1在指定的路径C:\ Program Files \ Java \ jdk-9.0.1 /../ lib / tools.jar
据我所知,tools.jar(和rt.jar)已从Java 9 JDK中删除。我想知道是否有办法让Maven AspectJ插件在没有tools.jar的情况下使用Java 9?
以下是我的插件定义及版本信息:
<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>
答案 0 :(得分:4)
在1.11.1
发行到Maven Central之前,版本org.codehaus.mojo
使用snapshot build代替:
<groupId>com.github.m50d</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11.1</version>
答案 1 :(得分:3)
我刚刚发现了一个丑陋的技巧,让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 :(得分:1)
遇到同样的问题,问题是这个传递依赖在默认情况下在aspectj-maven-plugin中是活动的。
使用此PR修复了它 https://github.com/mojohaus/aspectj-maven-plugin/pull/35
答案 3 :(得分:0)
你检查过最新的插件版本吗?
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>