Repository navigation
Auto-detect module source hierarchy and skip main artifact at install - #468
Conversation
When a project uses module source hierarchy (<source><module>…), the JAR plugin produces one JAR per JPMS module as attached artifacts and never assigns a file to the main artifact. The install plugin then fails because the main artifact path is a directory. Auto-detect this case by checking whether any source root declares a module (via ProjectManager.getSourceRoots() / SourceRoot.module()), and skip the main artifact from the install request — installing only the POM and the per-module JARs. This is a workaround for Maven 4.0. The proper fix is tracked in apache/maven#13396 (Packaging.producesMainArtifact() API for 4.1.0). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
The detection logic in usesModuleSourceHierarchy is sound, but there is one concrete gap worth addressing.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Both previous findings are addressed.
- Detection logic is correct: filters enabled source roots, checks module presence, and is placed after the
attachedArtifacts.isEmpty()guard — so multi-module projects with attached artifacts (e.g. uber-jars) still go through the normal path. toInstallmutation is safe: the for-each loop iteratesinstallables(immutable view) while removing from a separateArrayListcopy — noConcurrentModificationExceptionrisk.- Warning consolidation preserves the original semantics.
- Test validates the fix: pre-fix code would throw
MojoExceptionon the!allowIncompleteProjectsbranch; post-fix the newelse if (usesModuleSourceHierarchy(...))intercedes first.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
desruisseaux
left a comment
There was a problem hiding this comment.
I tested on my multi-modules project and it worked perfectly well. Thanks!
One small wish (unrelated to this issue): create hard links instead of copying the files.
|
Implemented in apache/maven-resolver#2198 — hard links are now the default in |
|
@gnodet Please assign appropriate label to PR according to the type of change. |
Summary
<source><module>…), the JAR plugin produces one JAR per JPMS module as attached artifacts and never assigns a file to the main artifact — the install plugin then crashes with "Is a directory"ProjectManager.getSourceRoots()for anySourceRootwithmodule().isPresent(), and removes the main artifact from the install requestHow it differs from #466
PR #466 requires
allowIncompleteProjects=true— a flag whose name and semantics don't match the module source hierarchy use case. This PR auto-detects instead:allowIncompleteProjects=trueallowIncompleteProjectsbehaviorContext
This is a workaround for Maven 4.0 (API is frozen). The proper fix is tracked in apache/maven#13396 — a
Packaging.producesMainArtifact()API for Maven 4.1.0 that would let the JAR plugin explicitly signal "no main artifact", eliminating the need for detection in the install plugin.Test plan
moduleSourceHierarchySkipsMainArtifact— sets up source roots with a module, attaches a module JAR, sets main artifact path to a directory, verifies only POM + module JAR are installed🤖 Generated with Claude Code