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 d1ff1d7
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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 +154,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:*:[1.6.2]</exclude>
</excludes>
</dependencyConvergence>
</rules>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.enforcer.its</groupId>
<artifactId>dependency-convergence</artifactId>
<version>1.0.0</version>
<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>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>enforce</id>
<configuration>
<rules>
<!-- if there are no includes, assume everything is included and apply excludes -->
<dependencyConvergence>
<excludes>
<excludes>org.slf4j:*:[1.6.1,1.6.2]</excludes>
</excludes>
</dependencyConvergence>
</rules>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

0 comments on commit d1ff1d7

Please sign in to comment.