gnodet commented on PR #1091: URL: https://github.com/apache/maven-plugin-tools/pull/1091#issuecomment-4161267136
## Investigation: Resource order inversion in Maven 4 compatibility layer Following the investigation of the resource ordering issue observed in [maven-source-plugin#281](https://github.com/apache/maven-source-plugin/pull/281), here is the root cause analysis. ### The problem When a Maven 3 plugin (such as `maven-remote-resources-plugin`) dynamically adds a resource via `project.getResources().add(resource)` or `project.addResource(resource)`, the resource is added to the internal `LinkedHashSet<SourceRoot> sources`, but **not** to the model's `Build.resources`. ### Why this causes the order inversion The `maven-source-plugin` (3.x) in its `createArchiver()` method uses `project.getBuild().getResources()` (the model) to find the `maven-shared-archive-resources` directory and add META-INF files **first** in the JAR. In Maven 4, `getBuild().getResources()` doesn't see dynamically added resources → META-INF files are not added first → they end up at the end. ### In Maven 3 `project.getResources()` and `project.getBuild().getResources()` return the **same** mutable list. Both see dynamically added resources. ### In Maven 4 `project.getResources()` returns a virtual list based on `sources`, while `project.getBuild().getResources()` returns a WrapperList based on the model. They are **disconnected**. ### Fix A change in `MavenProject.addResource()` (impl/maven-core): also propagate the addition to the model's Build to maintain consistency: ```java private void addResource(ProjectScope scope, Resource resource) { addSourceRoot(new DefaultSourceRoot(getBaseDirectory(), scope, resource.getDelegate())); // Also update the model's Build to maintain compatibility if (scope == ProjectScope.MAIN) { getModelBuild().addResource(resource); } else { getModelBuild().addTestResource(resource); } } ``` This ensures that resources added dynamically by plugins are visible through both access paths (`project.getResources()` and `project.getBuild().getResources()`), matching Maven 3 behavior. _Claude Code on behalf of Guillaume Nodet_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
