【问题标题】:How to resolve maven EnforcedBytecodeVersion failure?如何解决 maven EnforcedBytecodeVersion 失败?
【发布时间】:2018-08-14 22:13:41
【问题描述】:

由于某些符合 1.9 的类而尝试运行 maven enforcer 时失败,而整个项目仅限于 1.8。以下是日志的堆栈跟踪。该特定依赖项正在由另一个 jar 提取,该 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

【问题讨论】:

    标签: java maven maven-3 maven-enforcer-plugin


    【解决方案1】:

    您似乎误解了 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>
    

    【讨论】:

    • 我们如何在执行器中排除特定的东西?
    • @Vishwaksena 相应地更新了我的答案。
    【解决方案2】:

    通过在子 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-02
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 2020-08-03
      • 1970-01-01
      相关资源
      最近更新 更多