Class PedanticDependencyOrderEnforcer

java.lang.Object
com.github.ferstl.maven.pomenforcers.AbstractPedanticEnforcer
com.github.ferstl.maven.pomenforcers.PedanticDependencyOrderEnforcer
All Implemented Interfaces:
org.apache.maven.enforcer.rule.api.EnforcerRule, org.apache.maven.enforcer.rule.api.EnforcerRule2

public class PedanticDependencyOrderEnforcer extends AbstractPedanticEnforcer
This enforcer makes sure that all artifacts in your dependencies section are ordered. The ordering can be defined by any combination of scope, groupId and artifactId. Each of these attributes may be given a priority.
 ### Example
     <rules>
       <dependencyOrder implementation="com.github.ferstl.maven.pomenforcers.PedanticDependencyOrderEnforcer">
         <!-- order by scope, groupId and artifactId (default) -->
         <orderBy>scope,groupId,artifactId</orderBy>
         <!-- runtime scope should occur before provided scope -->
         <scopePriorities>compile,runtime,provided</scopePriorities>
         <!-- all group IDs starting with com.myproject and com.mylibs should occur first -->
         <groupIdPriorities>com.myproject,com.mylibs</groupIdPriorities>
         <!-- all artifact IDs starting with commons- and utils- should occur first -->
         <artifactIdPriorities>commons-,utils-</artifactIdPriorities>
       </dependencyOrder>
     </rules>
 
Since:
1.0.0
Enforcer Rule ID:
PedanticEnforcerRule.DEPENDENCY_ORDER
  • Constructor Details

    • PedanticDependencyOrderEnforcer

      public PedanticDependencyOrderEnforcer()
  • Method Details

    • accept

      protected void accept(PedanticEnforcerVisitor visitor)
      Specified by:
      accept in class AbstractPedanticEnforcer
    • getDescription

      protected PedanticEnforcerRule getDescription()
      Specified by:
      getDescription in class AbstractPedanticEnforcer
    • getDeclaredDependencies

      protected Collection<DependencyModel> getDeclaredDependencies()
    • getMavenDependencies

      protected Collection<org.apache.maven.model.Dependency> getMavenDependencies(org.apache.maven.project.MavenProject project)
    • reportError

      protected void reportError(ErrorReport report, Collection<DependencyModel> resolvedDependencies, Collection<DependencyModel> sortedDependencies)
    • setOrderBy

      public void setOrderBy(String dependencyElements)
      Comma-separated list of dependency elements that defines the ordering.
      Parameters:
      dependencyElements - Comma-separated list of dependency elements that defines the ordering.
      Since:
      1.0.0
      Enforcer Configuration Parameter
      Default Value:
      scope, groupId, artifactId
    • setGroupIdPriorities

      public void setGroupIdPriorities(String groupIds)
      Comma-separated list of group IDs that should be listed first in the dependencies declaration. All group IDs that start with any of the prioritized group IDs in the given list, are required to be located first in the dependencies section.
      Parameters:
      groupIds - Comma separated list of group IDs.
      Since:
      1.0.0
      Enforcer Configuration Parameter
      Default Value:
      n/a
    • setArtifactIdPriorities

      public void setArtifactIdPriorities(String artifactIds)
      Comma-separated list of artifact IDs that should be listed first in the dependencies declaration. All artifact IDs that start with any of the prioritized IDs in the given list, are required to be located first in the dependencies section.
      Parameters:
      artifactIds - Comma separated list of artifact IDs.
      Since:
      1.0.0
      Enforcer Configuration Parameter
      Default Value:
      n/a
    • setScopePriorities

      public void setScopePriorities(String scopes)
      Comma-separated list of scopes that should be listed first in the dependencies declaration. All scopes that equal any of the scopes in the given list, are required to be located first in the dependencies section.
      Parameters:
      scopes - Comma separated list of scopes.
      Since:
      1.0.0
      Enforcer Configuration Parameter
      Default Value:
      import, compile, provided, runtime, system, test
    • doEnforce

      protected final void doEnforce(ErrorReport report)
      Specified by:
      doEnforce in class AbstractPedanticEnforcer