Skip to content

Commit

Permalink
Make excludes configurable via property
Browse files Browse the repository at this point in the history
  • Loading branch information
mstahv authored and wilkinsona committed Apr 11, 2024
1 parent 2f3cf56 commit 58fc8f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,25 @@ void whenAnEntryIsExcludedItDoesNotAppearInTheRepackagedJar(MavenBuild mavenBuil
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-context")
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-core")
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-jcl")
.doesNotHaveEntryWithName("BOOT-INF/lib/servlet-api-2.5.jar");
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-");
});
}

@TestTemplate
void whenAnEntryIsExcludedWithPropertyItDoesNotAppearInTheRepackagedJar(MavenBuild mavenBuild) {
mavenBuild.project("jar")
.systemProperty("spring-boot.excludes", "jakarta.servlet:jakarta.servlet-api")
.goals("install")
.execute((project) -> {
File repackaged = new File(project, "target/jar-0.0.1.BUILD-SNAPSHOT.jar");
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-context")
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-core")
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-jcl")
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-");
});
}

@TestTemplate
void whenAGroupIsExcludedNoEntriesInThatGroupAppearInTheRepackagedJar(MavenBuild mavenBuild) {
mavenBuild.project("jar-exclude-group").goals("install").execute((project) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
/**
* Collection of artifact definitions to exclude. The {@link Exclude} element defines
* mandatory {@code groupId} and {@code artifactId} properties and an optional
* {@code classifier} property.
* {@code classifier} property. If passing in excludes as a property the syntax is
* <pre>-Dspring-boot.excludes=groupId1:artifactId1,groupId2:artifactId2:optional-qualifier</pre>
* @since 1.1.0
*/
@Parameter(property = "spring-boot.excludes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.maven;

import org.springframework.util.Assert;

/**
* A model for a dependency to exclude.
*
Expand All @@ -24,4 +26,17 @@
*/
public class Exclude extends FilterableDependency {

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

}

0 comments on commit 58fc8f8

Please sign in to comment.