How to resolve maven EnforcedBytecodeVersion failure?

老子叫甜甜 提交于 2019-12-11 17:54:41

问题


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

回答1:


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 ...

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>



回答2:


By overriding the target bytecode to 1.9 in the child pom was able to resolve the enforcer issue as follows.

<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>


来源:https://stackoverflow.com/questions/51850449/how-to-resolve-maven-enforcedbytecodeversion-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!