Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using Maven, configuring the spring-boot.excludes or spring-boot-includes user properties causes the build to fail with "Cannot find default setter" #39837

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,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-");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change could result in the test passing when it should not. The exclude is targeting this dependency:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert it when merging.

});
}

@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-");
mstahv marked this conversation as resolved.
Show resolved Hide resolved
});
}

@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]);
}
}

}