EnforcedBytecodeVersion失败

EnforcedBytecodeVersion失败

本文介绍了如何解决Maven EnforcedBytecodeVersion失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试运行Maven强制执行器时,由于某些类符合1.9的类而导致失败,而整个项目都限制为1.8.以下是日志的堆栈跟踪.特定的依赖关系是由另一个jar提取的,因为它具有编译时间依赖关系,因此不能将其排除.

When trying to run maven enforcer getting a failure due to some classes conforming to 1.9 where as the entire project is confine dto 1.8. Following is the stack trace of the log. That specific dependency is being pulled by a different jar which can't be excluded as it has compile time dependency.

[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

推荐答案

这似乎是您误解了forceBytecodeversion的意图...它将检查所有依赖项,如果它们使用字节码来更新版本,则表示这意味着比JDK 8更高,仅仅提升maxJdkVersion并不能解决问题.问题与您正在使用的依赖项有关....

It seemed to be that you misunderstand the intention of enforceBytecodeversion...It will check all dependencies if they use byte code for a more recent version as stated which means higher than JDK 8 just lifting the maxJdkVersion is not solving the problem. The problem is related to the dependencies you are using ....

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从检入强制执行器规则中排除...

If you are sure all code in that dependency does not use JDK 9 specific things you have to exclude module-info.class from checking in enforcer rules...

更新:这可以通过使用跟随:

Update:This can be achieved by using the 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 EnforcedBytecodeVersion失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 22:06