在尝试运行Maven强制执行器时,由于某些类符合1.9的类而导致失败,而整个项目的范围则限制为1.8。以下是日志的堆栈跟踪。特定的依赖关系是由另一个jar提取的,因为它具有编译时间依赖关系,因此不能将其排除。
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java18:1.0
[INFO] Restricted to JDK 1.8 yet javax.json.bind:javax.json.bind-api:jar:1.0:compile contains module-info.class targeted to JDK 1.9
[WARNING] Rule 14: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:
Found Banned Dependency: javax.json.bind:javax.json.bind-api:jar:1.0
答案 0 :(得分:1)
通过将子pom中的目标字节码重写为1.9,可以解决强制执行程序问题,如下所示。
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.9</maxJdkVersion>
</enforceBytecodeVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
答案 1 :(得分:1)
这似乎是您误解了强制字节码版本的意图...它将检查所有依赖项,如果它们使用字节代码来更新版本,则表示这意味着高于JDK 8,只是解除maxJdkVersion不能解决问题。问题与您正在使用的依赖项有关。
The dependency: javax.json.bin:javax.json.bind-api
contains a `module-info.class` file which is related to JDK 9 ...
如果您确定该依赖项中的所有代码均未使用JDK 9特定的功能,则必须从检入强制执行器规则中排除module-info.class
...
更新: 这可以通过使用following:
来实现。<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-bytecode-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.8</maxJdkVersion>
<ignoreClasses>
<ignoreClass>module-info</ignoreClass>
</ignoreClasses>
</enforceBytecodeVersion>
</rules>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
<version>1.0-beta-9</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
[...]
</project>