Skip to content

Commit 58fc8f8

Browse files
mstahvwilkinsona
authored andcommitted
Make excludes configurable via property
See gh-39837
1 parent 2f3cf56 commit 58fc8f8

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/JarIntegrationTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,25 @@ void whenAnEntryIsExcludedItDoesNotAppearInTheRepackagedJar(MavenBuild mavenBuil
175175
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-context")
176176
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-core")
177177
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-jcl")
178-
.doesNotHaveEntryWithName("BOOT-INF/lib/servlet-api-2.5.jar");
178+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-");
179179
});
180180
}
181181

182+
@TestTemplate
183+
void whenAnEntryIsExcludedWithPropertyItDoesNotAppearInTheRepackagedJar(MavenBuild mavenBuild) {
184+
mavenBuild.project("jar")
185+
.systemProperty("spring-boot.excludes", "jakarta.servlet:jakarta.servlet-api")
186+
.goals("install")
187+
.execute((project) -> {
188+
File repackaged = new File(project, "target/jar-0.0.1.BUILD-SNAPSHOT.jar");
189+
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
190+
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-context")
191+
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-core")
192+
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-jcl")
193+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-");
194+
});
195+
}
196+
182197
@TestTemplate
183198
void whenAGroupIsExcludedNoEntriesInThatGroupAppearInTheRepackagedJar(MavenBuild mavenBuild) {
184199
mavenBuild.project("jar-exclude-group").goals("install").execute((project) -> {

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
8282
/**
8383
* Collection of artifact definitions to exclude. The {@link Exclude} element defines
8484
* mandatory {@code groupId} and {@code artifactId} properties and an optional
85-
* {@code classifier} property.
85+
* {@code classifier} property. If passing in excludes as a property the syntax is
86+
* <pre>-Dspring-boot.excludes=groupId1:artifactId1,groupId2:artifactId2:optional-qualifier</pre>
8687
* @since 1.1.0
8788
*/
8889
@Parameter(property = "spring-boot.excludes")

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Exclude.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.maven;
1818

19+
import org.springframework.util.Assert;
20+
1921
/**
2022
* A model for a dependency to exclude.
2123
*
@@ -24,4 +26,17 @@
2426
*/
2527
public class Exclude extends FilterableDependency {
2628

29+
// Maven looks for this public method if giving excludes as property
30+
// e.g. -Dspring-boot.excludes=myGroupId:myArtifactId:my-optional-classifier,foo:baz
31+
public void set(String propertyInput) {
32+
String[] parts = propertyInput.split(":");
33+
Assert.isTrue(parts.length == 2 || parts.length == 3,
34+
"Exclude must be in the form groupId:artifactId:optional-classifier");
35+
setGroupId(parts[0]);
36+
setArtifactId(parts[1]);
37+
if (parts.length == 3) {
38+
setClassifier(parts[2]);
39+
}
40+
}
41+
2742
}

0 commit comments

Comments
 (0)