Skip to content

fix: preserve processor path types across conflict resolution#11805

Merged
desruisseaux merged 1 commit intoapache:masterfrom
mariuszs:pr-11380
Mar 28, 2026
Merged

fix: preserve processor path types across conflict resolution#11805
desruisseaux merged 1 commit intoapache:masterfrom
mariuszs:pr-11380

Conversation

@mariuszs
Copy link
Copy Markdown
Contributor

@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

@desruisseaux desruisseaux requested a review from cstamas March 16, 2026 13:04
@cstamas
Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@mariuszs mariuszs marked this pull request as draft March 19, 2026 16:18
@mariuszs mariuszs marked this pull request as ready for review March 19, 2026 16:33
@mariuszs
Copy link
Copy Markdown
Contributor Author

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

Sure, rebased on current master.

@cstamas
Copy link
Copy Markdown
Member

cstamas commented Mar 20, 2026

LGTM! Thanks @mariuszs

desruisseaux added a commit to Geomatys/maven-compiler-plugin that referenced this pull request Mar 27, 2026
…/fix/modular-processor-shared-deps but taking only the test (no change in the compiler code).

Instead, we rely on apache/maven#11805 for fixing the issue.
@desruisseaux
Copy link
Copy Markdown
Contributor

Are we ready for a merge? I just verified that when this patch is applied, the test provided by apache/maven-compiler-plugin#1042 is fixed without any need for a hack in the compiler code.

@mariuszs
Copy link
Copy Markdown
Contributor Author

Yep, I'm all set on my end.

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.
mariuszs added a commit to mariuszs/maven-compiler-plugin that referenced this pull request Mar 27, 2026
@desruisseaux
Copy link
Copy Markdown
Contributor

Hearing no comment, I will go ahead.

@desruisseaux desruisseaux merged commit ea308a5 into apache:master Mar 28, 2026
22 checks passed
@github-actions
Copy link
Copy Markdown

@desruisseaux Please assign appropriate label to PR according to the type of change.

@github-actions github-actions bot added this to the 4.1.0 milestone Mar 28, 2026
@desruisseaux desruisseaux added the bug Something isn't working label Mar 28, 2026
desruisseaux pushed a commit to apache/maven-compiler-plugin that referenced this pull request Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants