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

Conversation

mstahv
Copy link
Contributor

@mstahv mstahv commented Mar 5, 2024

The change makes excludes configurable via CLI.

For example this:

mvn install -Dspring-boot.excludes=foo:bar,foo:baz

Would equal to following pom.xml configuration:

<excludes>
    <exclude>
        <groupId>foo</groupId>
        <artifactId>bar</artifactId>
    </exclude>
    <exclude>
        <groupId>foo</groupId>
        <artifactId>baz</artifactId>
    </exclude>
</excludes>

@wilkinsona
Copy link
Member

I think this is a bug. We already expose the excludes as a property:

It's included in the documentation as well but it doesn't work:

$ mvn clean package -Dspring-boot.excludes=com.example:example-module
…
[INFO] --- spring-boot:2.7.18:repackage (repackage) @ example ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.886 s
[INFO] Finished at: 2024-03-06T09:58:08Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.7.18:repackage (repackage) on project test-spring-boot-2.7: Unable to parse configuration of mojo org.springframework.boot:spring-boot-maven-plugin:2.7.18:repackage for parameter #: Cannot find default setter in class org.springframework.boot.maven.Exclude -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginConfigurationException

@wilkinsona wilkinsona changed the title Make excludes configurable via property When using Maven, configuring the spring-boot.excludes user property causes the build to fail with "Cannot find default setter in class org.springframework.boot.maven.Exclude" Mar 6, 2024
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 6, 2024
@wilkinsona wilkinsona added this to the 3.1.x milestone Mar 6, 2024
@mstahv
Copy link
Contributor Author

mstahv commented Mar 6, 2024

Now that it works (after this change) and I have the branch open in my NetBeans, should I also add an example of the property syntax to the doc 🤔 Or is it too obvious?

@mstahv
Copy link
Contributor Author

mstahv commented Mar 6, 2024

Additional note: the string syntax also doesn't in this change yet support classifier. Not sure if very often needed though 🤷‍♂️

@wilkinsona wilkinsona added the for: merge-with-amendments Needs some changes when we merge label Mar 6, 2024
@wilkinsona
Copy link
Member

Yes, please. An example in the docs would be good. I think we should also assert the format in the setter with something like this:

Assert.isTrue(parts.length == 2, "Exclude must be in the form groupId:artifactId");

Some tests would be very welcome too please.

@wilkinsona
Copy link
Member

wilkinsona commented Mar 6, 2024

the string syntax also doesn't in this change yet support classifier

That's a good point. I think classifiers should be supported otherwise the property doesn't meet its goal of providing an alternative to XML-based configuration. My proposed assertion above would have to be updated to take this into account.

@mstahv
Copy link
Contributor Author

mstahv commented Mar 6, 2024

Yeah, I think at least some integration test at least. @snicoll just hinted me to the correct directory 👍

mstahv added 2 commits March 6, 2024 13:14
 * JavaDoc showing the syntax
 * Support for optional classifier
 * More meaningful error with invalid parameters
Also fixed a related existing test that has been false positive since spring boot 3.
@mstahv
Copy link
Contributor Author

mstahv commented Mar 6, 2024

✅ Discussed changes in. Also fixed a related IT that had been false positive since Spring Boot 3.

@mstahv
Copy link
Contributor Author

mstahv commented Mar 27, 2024

@wilkinsona Was there still something missing from this PR. Would love to get forward with my prototype that would require this, but wouldn't like to work with own snapshots (testing would be deployments to could environments that'd build my apps with buildpacks...).

@wilkinsona
Copy link
Member

No, nothing's missing from the PR, we just have a lot on at the moment. We'll get to this as soon as we can. Thanks for your patience in the meantime.

@@ -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.

@wilkinsona wilkinsona self-assigned this Apr 11, 2024
@wilkinsona wilkinsona changed the title When using Maven, configuring the spring-boot.excludes user property causes the build to fail with "Cannot find default setter in class org.springframework.boot.maven.Exclude" When using Maven, configuring the spring-boot.excludes or spring-boot-includes user properties causes the build to fail with "Cannot find default setter" Apr 11, 2024
@wilkinsona wilkinsona modified the milestones: 3.1.x, 3.1.11 Apr 11, 2024
wilkinsona pushed a commit that referenced this pull request Apr 11, 2024
wilkinsona added a commit that referenced this pull request Apr 11, 2024
wilkinsona added a commit that referenced this pull request Apr 11, 2024
@wilkinsona
Copy link
Member

Thanks, @mstahv. While merging this, I realised that includes had the same problem. I've fixed those too in baf5a7f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: merge-with-amendments Needs some changes when we merge type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants