Enforce Bytecode Version
This rule checks the dependencies transitively and fails if any class of any dependency is having its bytecode version higher than the one specified.
The following parameters are supported by this rule:
- maxJdkVersion - the maximum target jdk version (e.g. 8, 11, 17, 21...)
- maxJavaMajorVersionNumber - an integer indicating the maximum bytecode major version number (cannot be specified if maxJdkVersion is present)
- maxJavaMinorVersionNumber - an integer indicating the maximum bytecode minor version number (cannot be specified if maxJdkVersion is present)
- includes, excludes - optional lists of artifact patterns to include or exclude ([groupId]:[artifactId]:[type]:[version] with wildcards and optional segments)
- ignoreClasses - a list of classes to ignore bytecode version problems. Wildcards can be specified using the * character.
- scopes - a list of scopes (e.g. test, provided) to include when scanning artifacts
- ignoredScopes - a list of scopes (e.g. test, provided) to ignore when scanning artifacts
- ignoreOptionals - a boolean, if
true
all dependencies which have<optional>true</optional
> are ignored. - searchTransitive - a boolean, specify if transitive dependencies should be searched (default) or only look at direct dependencies.
- strict - a boolean, if
true
process module-info and Multi-Release JAR classes
Note Sample Plugin Configuration:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version> <!-- find the latest version at http://maven.apache.org/plugins/maven-enforcer-plugin/ -->
<executions>
<execution>
<id>enforce-bytecode-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.7</maxJdkVersion>
<excludes>
<exclude>org.mindrot:jbcrypt</exclude>
</excludes>
</enforceBytecodeVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
<version>1.9.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
[...]
</project>
Trademarks
Apache, Apache Maven, Maven and the Apache feather logo are trademarks of The Apache Software Foundation.