fix: propagate addResource() to model Build for Maven 3 compat#11868
Draft
fix: propagate addResource() to model Build for Maven 3 compat#11868
Conversation
When a Maven 3 plugin dynamically adds a resource via project.addResource() or project.getResources().add(), the resource was only added to the internal sources set but not to the model's Build.resources. This caused project.getBuild().getResources() to be out of sync with project.getResources(), breaking plugins like maven-source-plugin that access resources through the Build model. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Also sync the model's Build.resources after project building so that project.getBuild().getResources() is consistent with project.getResources() even when resources are defined via <sources> (Maven 4.1.0 model) rather than legacy <resources>. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Avoid syncing Build.resources for legacy projects to prevent Path.toString() from converting forward slashes to backslashes on Windows (fixes PomConstructionTest.testTargetPathResourceRegression). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
project.addResource()orproject.getResources().add(), propagate the change to the model'sBuild.resourcesso thatproject.getBuild().getResources()stays in sync withproject.getResources()Build.resources/Build.testResourcesfrom thesourcesset so that resources defined via<sources>(Maven 4.1.0) are also visible throughproject.getBuild().getResources()Root cause
In Maven 3,
project.getResources()andproject.getBuild().getResources()return the same mutable list. In Maven 4's compatibility layer, they are disconnected:getResources()returns a virtual list backed by the internalsourcesset, whilegetBuild().getResources()returns a WrapperList backed by the model.When
maven-remote-resources-pluginadds a resource directory, only thesourcesset was updated. Themaven-source-plugin'screateArchiver()method usesproject.getBuild().getResources()to find themaven-shared-archive-resourcesdirectory and add META-INF files first in the JAR — but in Maven 4 it couldn't find it, causing the META-INF entries to appear at the end instead of the beginning.Additionally, when resources are defined via
<sources>(Maven 4.1.0 model), they were only added to thesourcesset but not reflected inBuild.resources, making them invisible to Maven 3 plugins accessing resources viaproject.getBuild().getResources().See: apache/maven-source-plugin#281
Test plan
ResourceIncludeTestpasses (10 tests)maven-coretest suite passes (545 tests)🤖 Generated with Claude Code