Skip to content

fix: preserve processor path types across conflict resolution#11805

Open
mariuszs wants to merge 2 commits intoapache:masterfrom
mariuszs:pr-11380
Open

fix: preserve processor path types across conflict resolution#11805
mariuszs wants to merge 2 commits intoapache:masterfrom
mariuszs:pr-11380

Conversation

@mariuszs
Copy link

@mariuszs mariuszs commented Mar 16, 2026

Summary

Fixes the issue described in maven-compiler-plugin#1042 (comment): when a dependency is both a direct dep (e.g., modular-jar) and a transitive dep of a processor, ConflictResolver removes the transitive occurrence before TypeDeriver can assign processor path types. The artifact ends up only on --module-path, missing from --processor-module-path.

This builds on PR #11380 which introduced TypeDeriver.

Root cause

ConflictMarker keys on groupId:artifactId:extension:classifier. Since modular-jar and modular-processor both have extension=jar, classifier="", they share the same conflict key. ConflictResolver (which runs before TypeDeriver) picks one winner and removes the loser entirely (verbosity=NONE). TypeDeriver then never sees the transitive processor occurrence.

Fix: two-phase approach (no maven-resolver changes needed)

Phase Transformer When What
1 TypeCollector Before ConflictResolver Walks pre-conflict tree, records {GA:ext:cls → derived processor type} in context
2 ProcessorTypeMerger (in TypeDeriver) After ConflictResolver Reads context, sets PROCESSOR_TYPE property on surviving nodes that need both paths
3 DefaultDependencyResolverResult At path assignment Reads PROCESSOR_TYPE, adds artifact to processor paths too

TypeCollector short-circuits when no processor-type direct deps exist, so builds without processors pay zero cost.

Changes

  • New TypeCollector transformer (impl + compat)
  • New PROCESSOR_TYPE artifact property in MavenArtifactProperties
  • TypeDeriver enhanced with ProcessorTypeMerger inner visitor
  • DefaultDependencyResolverResult.addDependency() handles PROCESSOR_TYPE
  • MavenSessionBuilderSupplier wires TypeCollector before ConflictResolver

Test plan

  • New test TypeDeriverWithConflictResolutionTest.sharedDependencyLosesProcessorType — reproduces the exact scenario and verifies the fix
  • Control test typeDeriverAloneWorksCorrectly — proves TypeDeriver logic is correct in isolation
  • Existing TypeDeriverTest (2 tests) still pass
  • Checkstyle: 0 violations
  • End-to-end IT in maven-compiler-plugin@f8a6fd1 (modular-processor-shared-dep) — 3-module project with shared-lib as both modular-jar direct dep and transitive dep of modular-processor, verifies javac compiles successfully

Related

cstamas and others added 2 commits December 16, 2025 19:29
Instead to "smear" this feature across Maven and Resolver classes,
for start let's keep it "confined" with single class: the
TypeDeriver.

Later we can see where to go further with it.

Supersedes apache#11373
When a dependency is both a direct dep (e.g., modular-jar) and a
transitive dep of a processor, ConflictResolver removes the transitive
occurrence before TypeDeriver can assign processor path types. This
causes the artifact to appear only on --module-path, not on
--processor-module-path (maven-compiler-plugin#1039).

Fix: two-phase approach without changing maven-resolver:
- TypeCollector runs BEFORE ConflictResolver, records which artifacts
  are transitive deps of processors in the transformation context
- TypeDeriver (after ConflictResolver) reads the context and sets
  PROCESSOR_TYPE property on surviving nodes that need both paths
- DefaultDependencyResolverResult reads PROCESSOR_TYPE and adds the
  artifact to processor paths as well

TypeCollector short-circuits when no processor-type direct deps exist,
so the vast majority of builds pay zero cost.
@desruisseaux desruisseaux requested a review from cstamas March 16, 2026 13:04
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