diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java index 9ae658f1c8..5f6a8aafc8 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java @@ -28,7 +28,6 @@ import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterExceptio import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter; import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; -import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter; /** * A base mojo filtering the dependencies of the project. @@ -48,14 +47,14 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo { private List excludes; /** - * Comma separated list of groupId names to exclude. + * Comma separated list of groupId names to exclude (exact match). * @since 1.1 */ @Parameter(property = "excludeGroupIds", defaultValue = "") private String excludeGroupIds; /** - * Comma separated list of artifact names to exclude. + * Comma separated list of artifact names to exclude (exact match). * @since 1.1 */ @Parameter(property = "excludeArtifactIds", defaultValue = "") @@ -96,7 +95,7 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo { } filters.addFilter(new ArtifactIdFilter("", cleanFilterConfig(this.excludeArtifactIds))); - filters.addFilter(new GroupIdFilter("", cleanFilterConfig(this.excludeGroupIds))); + filters.addFilter(new MatchingGroupIdFilter(cleanFilterConfig(this.excludeGroupIds))); if (this.excludes != null) { filters.addFilter(new ExcludeFilter(this.excludes)); } diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/MatchingGroupIdFilter.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/MatchingGroupIdFilter.java new file mode 100644 index 0000000000..a2f2632d26 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/MatchingGroupIdFilter.java @@ -0,0 +1,28 @@ +package org.springframework.boot.maven; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactFeatureFilter; + +/** + * An {@link org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter + * ArtifactsFilter} that filters by matching groupId. + * + * Preferred over the {@link org.apache.maven.shared.artifact.filter.collection.GroupIdFilter} due + * to that classes use of {@link String#startsWith} to match on prefix. + * + * @author Mark Ingram + * @since 1.1 + */ +public class MatchingGroupIdFilter extends AbstractArtifactFeatureFilter { + + /** + * Create a new instance with the CSV groupId values that should be excluded. + */ + public MatchingGroupIdFilter(String exclude) { + super("", exclude); + } + + protected String getArtifactFeature(Artifact artifact) { + return artifact.getGroupId(); + } +} diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java index 1e9157a2a7..4d51f76559 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java @@ -51,6 +51,19 @@ public class DependencyFilterMojoTests { assertSame("Wrong filtered artifact", artifact, artifacts.iterator().next()); } + @Test + public void filterGroupIdExactMatch() throws MojoExecutionException { + TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo( + Collections.emptyList(), "com.foo", ""); + + Artifact artifact = createArtifact("com.foo.bar", "one"); + Set artifacts = mojo.filterDependencies( + createArtifact("com.foo", "one"), createArtifact("com.foo", "two"), + artifact); + assertEquals("wrong filtering of artifacts", 1, artifacts.size()); + assertSame("Wrong filtered artifact", artifact, artifacts.iterator().next()); + } + private Artifact createArtifact(String groupId, String artifactId) { Artifact a = mock(Artifact.class); given(a.getGroupId()).willReturn(groupId);