Class BanDuplicateClasses

  • All Implemented Interfaces:
    org.apache.maven.enforcer.rule.api.EnforcerRuleBase

    @Named("banDuplicateClasses")
    public class BanDuplicateClasses
    extends AbstractResolveDependencies
    Bans duplicate classes on the classpath.
    • 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 the module-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
      If false then the rule will fail at the first duplicate, if true then the rule will fail at the end.
      private java.lang.String[] ignoreClasses
      List of classes to ignore.
      private boolean ignoreWhenIdentical
      If true do not fail the build when duplicate classes exactly match each other.
      private java.lang.String message
      The failure message
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected BanDuplicateClasses​(org.apache.maven.execution.MavenSession session, org.eclipse.aether.RepositorySystem repositorySystem)  
    • 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, InputStreamSupplier inputStreamSupplier, java.util.Map<java.lang.String,​ClassesWithSameName> classesSeen, java.util.Set<java.lang.String> duplicateClasses, java.util.Collection<AbstractResolveDependencies.IgnorableDependency> ignores)  
      org.apache.maven.enforcer.rule.api.EnforcerLogger getLog()  
      protected void handleArtifacts​(java.util.Set<org.apache.maven.artifact.Artifact> artifacts)  
      void setLog​(org.apache.maven.enforcer.rule.api.EnforcerLogger arg0)  
      • Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRule

        getCacheId, getLevel
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 the module-info.class will be duplicated in any jar file. Furthermore in use cases for multi release jars the module-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
        If false then the rule will fail at the first duplicate, if true 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.
      • ignoreWhenIdentical

        private boolean ignoreWhenIdentical
        If true 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 is false.
    • Constructor Detail

      • BanDuplicateClasses

        @Inject
        protected BanDuplicateClasses​(org.apache.maven.execution.MavenSession session,
                                      org.eclipse.aether.RepositorySystem repositorySystem)
    • 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 class AbstractResolveDependencies
        Throws:
        org.apache.maven.enforcer.rule.api.EnforcerRuleException
      • checkAndAddName

        private void checkAndAddName​(org.apache.maven.artifact.Artifact artifact,
                                     java.lang.String pathToClassFile,
                                     InputStreamSupplier inputStreamSupplier,
                                     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,
                                     java.io.IOException
        Throws:
        org.apache.maven.enforcer.rule.api.EnforcerRuleException
        java.io.IOException
      • setLog

        public void setLog​(org.apache.maven.enforcer.rule.api.EnforcerLogger arg0)
        Specified by:
        setLog in interface org.apache.maven.enforcer.rule.api.EnforcerRuleBase
      • getLog

        public org.apache.maven.enforcer.rule.api.EnforcerLogger getLog()