javamavenmaven-3maven-enforcer-plugin

How to resolve maven EnforcedBytecodeVersion failure?


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

Solution

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