Skip to content

Commit

Permalink
Allow exludes to apply when includes are not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
fdfea committed Nov 3, 2022
1 parent b5fdb11 commit e322900
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.maven.shared.dependency.graph.DependencyNode;
import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;


/**
* @author Brian Fox
*
Expand Down Expand Up @@ -132,7 +133,7 @@ public List<List<DependencyNode>> getConflictedVersionNumbers( List<String> incl
for ( List<DependencyNode> nodes : idsToNode.values() )
{
List<DependencyNode> filteredNodes = nodes;
if ( formattedIncludes != null && !formattedIncludes.isEmpty() )
if ( formattedIncludes != null || formattedExcludes != null )
{
filteredNodes = new ArrayList<>();
for ( DependencyNode node : nodes )
Expand All @@ -154,8 +155,8 @@ public List<List<DependencyNode>> getConflictedVersionNumbers( List<String> incl
private static boolean includeArtifact( Artifact artifact, List<String> includes, List<String> excludes )
throws EnforcerRuleException
{
boolean included = false;
if ( includes != null )
boolean included = includes == null || includes.isEmpty();
if ( !included )
{
for ( String pattern : includes )
{
Expand Down
10 changes: 4 additions & 6 deletions enforcer-rules/src/site/apt/dependencyConvergence.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,11 @@ and
By default, all dependency convergence errors are reported, and any single error will fail the build. If you want
to tune which dependency errors are reported and fail the build, you can add the following optional parameters:

* includes - A list of artifacts for which dependency convergence should be enforced. If empty, dependency
convergence will be enforced for all artifacts.
* includes - A list of artifacts for which dependency convergence should be enforced. Not specifying any includes
is interpreted the same as including all artifacts.

* excludes - A list of artifacts for which dependency convergence should not be enforced. These are exceptions
to the includes. In other words, excludes only subtract from artifacts that matched an included artifact.
If you want to enforce dependency convergence for all except a few artifacts, set the includes to <<<*>>> and
exclude the artifacts you want.
to the includes.

[]

Expand All @@ -158,4 +156,4 @@ and
<exclude>org.apache.commons:*:[3.4]</exclude>
</excludes>
</dependencyConvergence>
+---------------------------------------------
+---------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
<include>*</include>
</includes>
<excludes>
<excludes>org.slf4j:slf4j-api:[1.6.1]</excludes>
<excludes>org.slf4j:slf4j-api:[1.6.2]</excludes>
<excludes>org.slf4j:slf4j-api:[1.6.1,1.6.2]</excludes>
</excludes>
</dependencyConvergence>
</rules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
Expand All @@ -50,11 +55,10 @@
<id>enforce</id>
<configuration>
<rules>
<!-- if there are no includes, return all errors -->
<!-- if there are no includes, assume everything is included and apply excludes -->
<dependencyConvergence>
<includes/>
<excludes>
<exclude>org.slf4j</exclude>
<exclude>org.slf4j:slf4j-api:[1.6.2]</exclude>
</excludes>
</dependencyConvergence>
</rules>
Expand Down

0 comments on commit e322900

Please sign in to comment.