如何解决 Maven EnforcedBytecodeVersion 失败?
How to resolve maven EnforcedBytecodeVersion failure?
当尝试 运行 Maven 强制执行器由于某些 类 符合 1.9 而失败时,因为整个项目被限制为 dto 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
通过在子 pom 中将目标字节码覆盖为 1.9 能够解决 enforcer 问题,如下所示。
<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>
这似乎是你误解了 enforceBytecodeversion 的意图...如果他们使用字节码作为声明的更新版本,它将检查所有依赖项,这意味着高于 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>
当尝试 运行 Maven 强制执行器由于某些 类 符合 1.9 而失败时,因为整个项目被限制为 dto 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
通过在子 pom 中将目标字节码覆盖为 1.9 能够解决 enforcer 问题,如下所示。
<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>
这似乎是你误解了 enforceBytecodeversion 的意图...如果他们使用字节码作为声明的更新版本,它将检查所有依赖项,这意味着高于 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>