Skip to content

fix: preserve processor path types across conflict resolution#11805

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

fix: preserve processor path types across conflict resolution#11805
mariuszs wants to merge 5 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
@cstamas
Copy link
Member

cstamas commented Mar 19, 2026

Sorry for this, I rebased my PR without thinking and this one is now full of conflicts.

@desruisseaux
Copy link
Contributor

Hello @mariuszs . Would it be possible to rebase this pull request?

Resolve conflicts after PR apache#11380 was merged to master.
Our TypeCollector/ProcessorTypeMerger additions preserved on top.
@mariuszs mariuszs marked this pull request as draft March 19, 2026 16:18
- Replace full-tree DependencyVisitor with simple 2-level loop
  (only direct processor deps and their children matter)
- Replace derive() method with static DERIVE_MAP lookup
- Extract PROCESSOR_TYPE_IDS constant, reuse in ProcessorTypeMerger
- Lift processorPathTypesFor() sets to static finals
- Remove System.out.println from test
- Remove unused DependencyGraphDumper import from test
@mariuszs mariuszs marked this pull request as ready for review March 19, 2026 16:33
@mariuszs
Copy link
Author

Hello @mariuszs . Would it be possible to rebase this pull request?

Sure, rebased on current master.

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.

3 participants