Class EnforceBytecodeVersion
java.lang.Object
org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule
org.apache.maven.enforcer.rules.dependency.EnforceBytecodeVersion
- All Implemented Interfaces:
EnforcerRuleBase
@Priority(10)
@Named("enforceBytecodeVersion")
public class EnforceBytecodeVersion
extends AbstractStandardEnforcerRule
Enforcer rule that will check the bytecode version of each class of each dependency.
- Since:
- 3.6.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classInput is Dependency file, and it may have been inspected already, but, in multi-module environment the configuration may be different. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String[]Default ignores when validating against jdk invalid input: '<' 9 becausemodule-info.classwill always have level 1.9.Specify the excluded dependencies.Internal: strings (regexp expressions) are collected here to ignore matched classes.List of classes to fully ignore, interpreted as regular expression.List of dependency scopes, to ignore dependencies in it.private booleanIf set, will ignore optional dependencies of the project.Specify the included dependencies.private intIf unsure, don't use that parameter.private intThis parameter is here for potentially advanced use cases, but it seems like it is actually always 0.private StringJDK version as used for example in the maven-compiler-plugin: 8, 11 and so on.private StringCustom message, optional.private static final Patternprivate booleanOptimization to calculate same JAR with same options once per session, by default is enabled.private final ResolverUtilList of dependency scopes, to include dependencies in it.private booleanIf set, transitive hull of project is being processed, otherwise only direct dependencies.private final org.apache.maven.execution.MavenSessionprivate booleanProcess module-info and Multi-Release JAR classes iftrue. -
Constructor Summary
ConstructorsConstructorDescriptionEnforceBytecodeVersion(org.apache.maven.execution.MavenSession session, ResolverUtil resolverUtil) -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringConvert a wildcard into a regex.private List<org.eclipse.aether.graph.Dependency> checkDependencies(List<org.eclipse.aether.graph.Dependency> dependencies) (package private) static IntegerdecodeMajorVersion(String version) Visible for testing.private List<org.eclipse.aether.graph.Dependency> dependencyGraphToList(org.eclipse.aether.graph.DependencyNode root) voidexecute()This is the interface into the rule.private List<org.eclipse.aether.graph.Dependency> filterDependencies(List<org.eclipse.aether.graph.Dependency> dependencies) private StringisBadDependency(org.eclipse.aether.graph.Dependency d) private static StringperformCheck(EnforcerLogger log, EnforceBytecodeVersion.ChecksOptions options) (package private) static StringrenderVersion(int major, int minor) Visible for testing.private voidMethods inherited from class AbstractStandardEnforcerRule
formatLocation, getMessage, setMessageMethods inherited from class AbstractEnforcerRule
getCacheId, getLevel, getRuleNameMethods inherited from class AbstractEnforcerRuleBase
getLog, setLog
-
Field Details
-
DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9
Default ignores when validating against jdk invalid input: '<' 9 becausemodule-info.classwill always have level 1.9. -
MULTI_RELEASE
-
JDK_TO_MAJOR_VERSION_NUMBER_MAPPING
-
message
Custom message, optional. If configured, will be present on first line of the error message. -
maxJdkVersion
JDK version as used for example in the maven-compiler-plugin: 8, 11 and so on. If in need of more precise configuration please seemaxJavaMajorVersionNumberandmaxJavaMinorVersionNumberMandatory ifmaxJavaMajorVersionNumbernot specified. -
maxJavaMajorVersionNumber
private int maxJavaMajorVersionNumberIf unsure, don't use that parameter. Better look atmaxJdkVersion. Mandatory ifmaxJdkVersionis not specified. see http://en.wikipedia.org/wiki/Java_class_file#General_layout -
maxJavaMinorVersionNumber
private int maxJavaMinorVersionNumberThis parameter is here for potentially advanced use cases, but it seems like it is actually always 0.- See Also:
-
excludes
-
includes
Specify the included dependencies. This can be a list of artifacts in the formatgroupId[:artifactId][:version]. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
Includes override the exclude rules. It is meant to allow wide exclusion rules with wildcards and still allow a smaller set of includes.
For example, to ban all xerces except xerces-api -> exclude "xerces", include "xerces:xerces-api" -
ignoreClasses
-
scopes
-
ignoredScopes
-
ignoreOptionals
private boolean ignoreOptionalsIf set, will ignore optional dependencies of the project. -
searchTransitive
private boolean searchTransitiveIf set, transitive hull of project is being processed, otherwise only direct dependencies. Default istrue. -
strict
private boolean strictProcess module-info and Multi-Release JAR classes iftrue. -
processOncePerSession
private boolean processOncePerSessionOptimization to calculate same JAR with same options once per session, by default is enabled. -
ignorableClassesPatterns
-
session
private final org.apache.maven.execution.MavenSession session -
resolverUtil
-
-
Constructor Details
-
EnforceBytecodeVersion
@Inject EnforceBytecodeVersion(org.apache.maven.execution.MavenSession session, ResolverUtil resolverUtil)
-
-
Method Details
-
renderVersion
Visible for testing. -
decodeMajorVersion
-
execute
Description copied from class:AbstractEnforcerRuleThis is the interface into the rule. This method should throw an exception containing a reason message if the rule fails the check. The plugin will then decide based on the fail flag and rule level if it should stop or just log the message as a warning.- Specified by:
executein classAbstractEnforcerRule- Throws:
EnforcerRuleException- the enforcer rule exception
-
validateAndPopulateParameters
- Throws:
EnforcerRuleException
-
checkDependencies
private List<org.eclipse.aether.graph.Dependency> checkDependencies(List<org.eclipse.aether.graph.Dependency> dependencies) throws EnforcerRuleException - Throws:
EnforcerRuleException
-
isBadDependency
- Throws:
EnforcerRuleException
-
asRegex
-
performCheck
private static String performCheck(EnforcerLogger log, EnforceBytecodeVersion.ChecksOptions options) throws EnforcerRuleException - Throws:
EnforcerRuleException
-
dependencyGraphToList
private List<org.eclipse.aether.graph.Dependency> dependencyGraphToList(org.eclipse.aether.graph.DependencyNode root) -
filterDependencies
-