为什么 Maven 执行器会限制为 Java 1.6?

mvn test在我的项目上运行时,出现 JDK 版本错误。


这是输出:


[INFO] Scanning for projects...

[INFO] 

[INFO] -----------------------< net.rorynolan:Detrendr >-----------------------

[INFO] Building Detrendr 0.0.0.9003-SNAPSHOT

[INFO] --------------------------------[ jar ]---------------------------------

[INFO] 

[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-rules) @ Detrendr ---

[INFO] Adding ignorable dependency: null:jcodings:null

[INFO]   Adding ignore: org/jcodings/*

[INFO] Adding ignorable dependency: null:jnr-constants:null

[INFO]   Adding ignore: com/kenai/constantine/*

...

[INFO] Adding ignorable dependency: com.sun:tools:null

[INFO]   Adding ignore: *

[INFO] Restricted to JDK 1.6 yet org.junit.platform:junit-platform-commons:jar:1.3.1:test contains org/junit/platform/commons/JUnitException.class targeted to JDK 1.8

[INFO] Restricted to JDK 1.6 yet org.junit.jupiter:junit-jupiter-api:jar:5.3.1:test contains org/junit/jupiter/api/AssertArrayEquals.class targeted to JDK 1.8

[INFO] Restricted to JDK 1.6 yet org.junit.jupiter:junit-jupiter-engine:jar:5.3.1:test contains org/junit/jupiter/engine/Constants.class targeted to JDK 1.8

[INFO] Restricted to JDK 1.6 yet org.junit.platform:junit-platform-engine:jar:1.3.1:test contains org/junit/platform/engine/TestDescriptor.class targeted to JDK 1.8

[WARNING] Rule 5: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:

Found Banned Dependency: org.junit.platform:junit-platform-commons:jar:1.3.1

Found Banned Dependency: org.junit.jupiter:junit-jupiter-api:jar:5.3.1

Found Banned Dependency: org.junit.jupiter:junit-jupiter-engine:jar:5.3.1

Found Banned Dependency: org.junit.platform:junit-platform-engine:jar:1.3.1

Use 'mvn dependency:tree' to locate the source of the banned dependencies.

[INFO] ------------------------------------------------------------------------

...

但这就是我所拥有的。我尝试将 maven 执行器插件明确添加到我自己的插件中,pom.xml但无济于事。


慕无忌1623718
浏览 210回答 1
1回答

潇湘沐

您的项目pom的父级为:net.imagej:pom-imagej:13.2.0,其父级为org.scijava:pom-scijava:8.4.0,其中包含以下与 Java 版本相关的摘录:<scijava.jvm.version>1.6</scijava.jvm.version><plugin>&nbsp; <artifactId>maven-compiler-plugin</artifactId>&nbsp; <version>3.1</version>&nbsp; <!-- Require the Java 6 platform. -->&nbsp; <configuration>&nbsp; &nbsp; <source>${scijava.jvm.version}</source>&nbsp; &nbsp; <target>${scijava.jvm.version}</target>&nbsp; </configuration></plugin><plugin>&nbsp; <artifactId>maven-enforcer-plugin</artifactId>&nbsp; ...&nbsp; <enforceBytecodeVersion>&nbsp; &nbsp; <maxJdkVersion>${scijava.jvm.version}</maxJdkVersion>&nbsp; &nbsp; ...&nbsp; </enforceBytecodeVersion></plugin>&nbsp;&nbsp;因此,执行者规则及其对 Java 1.6 的坚持是通过您项目的出身继承的。这种对 Java 1.6 的限制与编译为 Java 1.8 的 JUnit5 库冲突。您也许可以在您自己的 POM 中覆盖执行器插件(请参阅Maven 文档combine.self="override"中的参考),但是您模块的祖父 ( org.scijava:pom-scijava:8.4.0) 明确声明它希望在 Java 1.6 上运行这一事实强烈表明任何此类覆盖都会导致问题。我认为更明智的课程将是以下之一:从 Junit5 降级到与 Java 1.6 兼容的 Junit4 版本将您的父 ( net.imagej:pom-imagej:13.2.0)版本升级到与 Java 8 兼容的版本,注意:它net.imagej:pom-imagej:13.2.0已经 3 岁了,因此您可能会发现升级到最新版本会使此问题消失。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java