Class BanDuplicateClasses
- java.lang.Object
-
- org.apache.maven.plugins.enforcer.AbstractMojoHausEnforcerRule
-
- org.apache.maven.plugins.enforcer.AbstractResolveDependencies
-
- org.apache.maven.plugins.enforcer.BanDuplicateClasses
-
- All Implemented Interfaces:
org.apache.maven.enforcer.rule.api.EnforcerRule
,org.apache.maven.enforcer.rule.api.EnforcerRule2
public class BanDuplicateClasses extends AbstractResolveDependencies
Bans duplicate classes on the classpath.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.maven.plugins.enforcer.AbstractResolveDependencies
AbstractResolveDependencies.IgnorableDependency
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String[]
DEFAULT_CLASSES_IGNORES
Default ignores which are needed for JDK 9, cause in JDK 9 and above themodule-info.class
will be duplicated in any jar file.private java.util.List<Dependency>
dependencies
List of dependencies for which you want to ignore specific classes.private boolean
findAllDuplicates
Iffalse
then the rule will fail at the first duplicate, iftrue
then the rule will fail at the end.private java.lang.String[]
ignoreClasses
List of classes to ignore.private boolean
ignoreWhenIdentical
Iftrue
do not fail the build when duplicate classes exactly match each other.private java.lang.String
message
The failure messageprivate java.util.List<java.lang.String>
scopes
Only verify dependencies with one of these scopes
-
Constructor Summary
Constructors Constructor Description BanDuplicateClasses()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkAndAddName(org.apache.maven.artifact.Artifact artifact, java.lang.String pathToClassFile, java.util.Map<java.lang.String,ClassesWithSameName> classesSeen, java.util.Set<java.lang.String> duplicateClasses, java.util.Collection<AbstractResolveDependencies.IgnorableDependency> ignores)
protected void
handleArtifacts(java.util.Set<org.apache.maven.artifact.Artifact> artifacts)
-
Methods inherited from class org.apache.maven.plugins.enforcer.AbstractResolveDependencies
asRegex, execute, getCacheId, getLog, isCacheable, isResultValid, isSearchTransitive
-
Methods inherited from class org.apache.maven.plugins.enforcer.AbstractMojoHausEnforcerRule
getLevel, setLevel
-
-
-
-
Field Detail
-
DEFAULT_CLASSES_IGNORES
private static final java.lang.String[] DEFAULT_CLASSES_IGNORES
Default ignores which are needed for JDK 9, cause in JDK 9 and above themodule-info.class
will be duplicated in any jar file. Furthermore in use cases for multi release jars themodule-info.class
is also contained several times.
-
message
private java.lang.String message
The failure message
-
ignoreClasses
private java.lang.String[] ignoreClasses
List of classes to ignore. Wildcard at the end accepted
-
findAllDuplicates
private boolean findAllDuplicates
Iffalse
then the rule will fail at the first duplicate, iftrue
then the rule will fail at the end.
-
dependencies
private java.util.List<Dependency> dependencies
List of dependencies for which you want to ignore specific classes.
-
scopes
private java.util.List<java.lang.String> scopes
Only verify dependencies with one of these scopes
-
ignoreWhenIdentical
private boolean ignoreWhenIdentical
Iftrue
do not fail the build when duplicate classes exactly match each other. In other words, ignore duplication if the bytecode in the class files match. Default isfalse
.
-
-
Method Detail
-
handleArtifacts
protected void handleArtifacts(java.util.Set<org.apache.maven.artifact.Artifact> artifacts) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
- Specified by:
handleArtifacts
in classAbstractResolveDependencies
- Throws:
org.apache.maven.enforcer.rule.api.EnforcerRuleException
-
checkAndAddName
private void checkAndAddName(org.apache.maven.artifact.Artifact artifact, java.lang.String pathToClassFile, java.util.Map<java.lang.String,ClassesWithSameName> classesSeen, java.util.Set<java.lang.String> duplicateClasses, java.util.Collection<AbstractResolveDependencies.IgnorableDependency> ignores) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
- Throws:
org.apache.maven.enforcer.rule.api.EnforcerRuleException
-
-