Skip to content

Conversation

gnodet
Copy link
Contributor

@gnodet gnodet commented Sep 9, 2025

Problem

When building modules in isolation (outside of the full reactor), the ReactorReader would read the build POM from the project-local repository instead of the consumer POM. Build POMs can contain invalid elements like <parent /> that are only valid during the build process, causing parsing errors when used as dependency POMs.

This results in warnings like:

[WARNING] The POM for org.apache.maven.its.gh11084:a:jar:1.0.0-SNAPSHOT is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model
    - [FATAL] 'parent.groupId' is missing. @ line 21, column 3
    - [FATAL] 'parent.artifactId' is missing. @ line 21, column 3

Solution

Modified the findModel method in the ReactorReader class to:

  1. First check the current reactor - If the project is in the current reactor session, use the model from the project (existing behavior)
  2. Then check the project-local repository - If the project is not in the current reactor, look for a consumer POM in the project-local repository
  3. Prefer consumer POMs - Use the same logic as findInProjectLocalRepository to prefer consumer POMs over build POMs

Benefits

  • Eliminates invalid POM warnings when building modules in isolation
  • Maintains backward compatibility - existing behavior for reactor builds is unchanged
  • Follows the existing pattern - uses the same consumer POM preference logic as findInProjectLocalRepository
  • Robust error handling - gracefully falls back if the consumer POM cannot be read

Testing

The fix has been verified with the integration test scenario MavenITgh11084ReactorReaderPreferConsumerPomTest which now passes without invalid POM warnings.

Fixes #11084


Pull Request opened by Augment Code with guidance from the PR author

…ving POMs

When only part of a reactor is built, ReactorReader mirrors artifacts into a project-local repo. If a module depends on another reactor module not in the current session, POM resolution may hit that repo. Today, the main POM path contains the build POM, which can include Maven-4 build-time constructs and be invalid as a repository POM (e.g., missing parent.*). As a result, dependency resolution can fail with fatal model errors.

Teach ReactorReader to prefer the consumer POM (classifier=consumer) for POM artifacts when present in the project-local repo, falling back to the main POM otherwise. This avoids consuming a build POM from the project-local repo without changing the repo contents or layout.
When building modules in isolation (outside of the full reactor), the
ReactorReader should prefer consumer POMs from the project-local repository
over build POMs to avoid invalid POM elements like <parent />.

The findModel method now:
1. First checks if the project is in the current reactor session
2. If not found, looks for a consumer POM in the project-local repository
3. Uses the same consumer POM preference logic as findInProjectLocalRepository

This eliminates 'invalid POM' warnings when building modules in isolation
while maintaining backward compatibility for reactor builds.

Fixes apachegh-11084
@gnodet gnodet added bug Something isn't working backport labels Sep 9, 2025
@gnodet gnodet merged commit 93b85b0 into apache:master Sep 17, 2025
36 of 38 checks passed
@github-actions github-actions bot added this to the 4.1.0 milestone Sep 17, 2025
gnodet added a commit to gnodet/maven that referenced this pull request Sep 17, 2025
* ReactorReader: prefer consumer POM from project-local repo when resolving POMs

When only part of a reactor is built, ReactorReader mirrors artifacts into a project-local repo. If a module depends on another reactor module not in the current session, POM resolution may hit that repo. Today, the main POM path contains the build POM, which can include Maven-4 build-time constructs and be invalid as a repository POM (e.g., missing parent.*). As a result, dependency resolution can fail with fatal model errors.

Teach ReactorReader to prefer the consumer POM (classifier=consumer) for POM artifacts when present in the project-local repo, falling back to the main POM otherwise. This avoids consuming a build POM from the project-local repo without changing the repo contents or layout.

* Fix ReactorReader to prefer consumer POMs over build POMs

When building modules in isolation (outside of the full reactor), the
ReactorReader should prefer consumer POMs from the project-local repository
over build POMs to avoid invalid POM elements like <parent />.

The findModel method now:
1. First checks if the project is in the current reactor session
2. If not found, looks for a consumer POM in the project-local repository
3. Uses the same consumer POM preference logic as findInProjectLocalRepository

This eliminates 'invalid POM' warnings when building modules in isolation
while maintaining backward compatibility for reactor builds.

Fixes apachegh-11084

* Fix

(cherry picked from commit 93b85b0)
@gnodet
Copy link
Contributor Author

gnodet commented Sep 17, 2025

💚 All backports created successfully

Status Branch Result
maven-4.0.x

Questions ?

Please refer to the Backport tool documentation

gnodet added a commit that referenced this pull request Sep 17, 2025
…11131)

ReactorReader: prefer consumer POMs over build POMs for isolated module builds

When building modules in isolation (outside of the full reactor), ReactorReader
now prefers consumer POMs from the project-local repository over build POMs.
This prevents dependency resolution failures caused by build POMs containing
Maven-4 build-time constructs that are invalid as repository POMs (e.g.,
missing parent elements).

The findModel method now:
1. First checks if the project is in the current reactor session
2. If not found, looks for a consumer POM in the project-local repository  
3. Uses the same consumer POM preference logic as findInProjectLocalRepository

This eliminates 'invalid POM' warnings when building modules in isolation
while maintaining backward compatibility for reactor builds without changing
repository contents or layout.

Fixes gh-11084
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-4.0.x bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant