Why would Maven enforcer restrict to Java 1.6?

Rory Nolan :

When I run mvn test on my project, I get a JDK version error.

Here's the output:

[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] ------------------------------------------------------------------------
...
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

My pom.xml is at https://github.com/rorynolan/ij_detrendr/blob/master/pom.xml.

There's a clue in mvn help:effective-pom

where I can see

<plugin>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>1.3.1</version>
  ...
  <rules>
    ...  
    <enforceBytecodeVersion>
      <maxJdkVersion>1.6</maxJdkVersion>
        <excludes>
          <exclude>com.headius:invokebinder</exclude>
          <exclude>com.sun:tools</exclude>
        </excludes>
      </enforceBytecodeVersion>
      <banCircularDependencies />
    </rules>
  </configuration>
</plugin>

But that's all I've got. I've tried adding the maven enforcer plugin explicitly to my own pom.xml but to no avail.

glytching :

Your project pom is parented by: net.imagej:pom-imagej:13.2.0 which is parented by org.scijava:pom-scijava:8.4.0 which contains the following excerpts relating to Java version:

<scijava.jvm.version>1.6</scijava.jvm.version>

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
  <!-- Require the Java 6 platform. -->
  <configuration>
    <source>${scijava.jvm.version}</source>
    <target>${scijava.jvm.version}</target>
  </configuration>
</plugin>

<plugin>
  <artifactId>maven-enforcer-plugin</artifactId>
  ...
  <enforceBytecodeVersion>
    <maxJdkVersion>${scijava.jvm.version}</maxJdkVersion>
    ...
  </enforceBytecodeVersion>
</plugin>  

So, the enforcer rule and its insistence on Java 1.6 is being inherited via your project's parentage.

This restriction to Java 1.6 conflicts with the JUnit5 libraries which were compiled to Java 1.8.

You could perhaps overide the enforcer plugin in your own POM (see references to combine.self="override" in the Maven docs) but the fact that your module's grandparent (org.scijava:pom-scijava:8.4.0) explicitly states that it expects to run on Java 1.6 strongly suggests that any such override will cause issues.

I think the wiser course would be one of the following:

  • Downgrade from Junit5 to a version of Junit4 which is compatible with Java 1.6
  • Upgrade the version of your parent (net.imagej:pom-imagej:13.2.0) to one which is compatible with Java 8, note: net.imagej:pom-imagej:13.2.0 is 3 years old so you might find that upgrading to the latest version makes this problem disappear.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=94222&siteId=1