Skip to content

core(consumer-pom): drop compile-only/test-only; map test-runtime -> test; adjust tests#11126

Closed
gnodet wants to merge 3 commits intoapache:masterfrom
gnodet:fix-11012
Closed

core(consumer-pom): drop compile-only/test-only; map test-runtime -> test; adjust tests#11126
gnodet wants to merge 3 commits intoapache:masterfrom
gnodet:fix-11012

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Sep 15, 2025

This PR updates the consumer POM generation to handle Maven 4–only test scopes in a way that is both minimal and Maven 3 compatible, while preserving relevant test runtime information for consumers.

Changes:

  • DefaultConsumerPomBuilder.transformDependencyForConsumerPom:
    • Omit Maven 4–only compile-only and test-only scopes (build-time only; not needed by downstream consumers).
    • Map Maven 4–only test-runtime to classic test for the consumer POM to retain the test runtime classpath in a Maven 3 compatible way.
    • Keep classic scopes (compile/provided/runtime/test/system) unchanged.
  • The transformation applies to both direct dependencies and dependencyManagement entries (via the existing transformation stream with null filtering).
  • Tests: Update ConsumerPomBuilderTest to reflect the new policy (compile-only and test-only omitted; test-runtime mapped to test; classic scopes unchanged). Existing SCM and consumer POM shape assertions remain.

Rationale:

  • The consumer POM targets the 4.0.0 model for Maven 3.x compatibility.
  • compile-only and test-only are build-time only and have no safe Maven 3 equivalent; dropping them keeps the consumer POM minimal.
  • test-runtime has no exact Maven 3 analog; mapping to test is the closest practical approximation and does not leak to downstream compile/runtime classpaths (test scope is non-transitive).

See #11012

@gnodet gnodet changed the title fix-11012 core(consumer-pom): drop compile-only/test-only; map test-runtime -> test; adjust tests Sep 16, 2025
@gnodet gnodet requested a review from cstamas September 16, 2025 09:51
}

// Handle new Maven 4 scopes when creating consumer POM
switch (scope) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks good, but one nit: could we do this programmatically? We do have mvn3 scope manager config and we do have mvn4 scope manager config as well.... I would really like to have all scopes managed at single place, unlike in mvn3 when they are smeared across many classes in many projects (maven, resolver, many plugins, etc)

Copy link
Contributor Author

@gnodet gnodet Sep 22, 2025

Choose a reason for hiding this comment

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

I moved the logic into Maven4ScopeManagerConfiguration. @cstamas is that what you were asking for ?

…test; adjust tests

- DefaultConsumerPomBuilder.transformDependencyForConsumerPom:
  - Omit Maven 4–only compile-only and test-only scopes from the consumer POM (build-time only, not needed by downstream consumers).
  - Map Maven 4–only test-runtime to the classic test scope for the consumer POM.
    This preserves the producer’s test runtime dependencies for consumers while staying compatible with the 4.0.0 model and Maven 3.x tooling.
  - Keep all classic scopes (compile/provided/runtime/test/system) unchanged.

- Apply the transformation consistently for both direct dependencies and dependencyManagement entries (existing streams already funnel through transformDependencyForConsumerPom and then filter nulls).

- Tests: update ConsumerPomBuilderTest to reflect policy:
  - compile-only → omitted
  - test-only → omitted
  - test-runtime → preserved and mapped to scope=test
  - classic scopes unchanged
  - existing SCM inheritance and consumer POM shape tests remain

Rationale:
- The consumer POM targets a 4.0.0 model to be consumable by Maven 3.x and other tools.
- compile-only and test-only are build-time-only concerns and have no safe Maven 3 equivalent; dropping them keeps the consumer POM minimal and compatible.
- test-runtime has no exact Maven 3 analog; mapping to test is the closest approximation and keeps relevant test runtime deps visible to consumers. test scope is non-transitive, so this does not leak into downstream compile/runtime classpaths.

Formatting:
- Ran Spotless on the affected module.
- Add mapScopeForMaven3ConsumerPom() method to Maven4ScopeManagerConfiguration
- Update DefaultConsumerPomBuilder to use consolidated scope mapping
- Remove separate ConsumerPomScopeMapper class to reduce code duplication
- Centralize all Maven 4 scope-related logic in single location
- Apply code formatting with spotless

This change improves code organization by consolidating related scope
mapping functionality while maintaining the same behavior for consumer
POM generation.
@gnodet gnodet marked this pull request as ready for review September 22, 2025 11:09
@gnodet
Copy link
Contributor Author

gnodet commented Sep 22, 2025

Superseded by #11163

@gnodet gnodet closed this Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants