Skip to content

Install the POM, not the JAR, for pom-packaged projects after jar:jar (#315) - #457

Merged
slachiewicz merged 3 commits into
apache:masterfrom
gnodet:fix/315-3.x
Nov 21, 2026
Merged

slachiewicz merged 3 commits into
apache:masterfrom
gnodet:fix/315-3.x

Conversation

@gnodet

@gnodet gnodet commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Problem

When jar:jar is invoked on a pom-packaged project, maven-jar-plugin 3.x calls project.getArtifact().setFile(jarFile), setting the main artifact's file to the produced JAR.

In InstallMojo.processProject(), for a pom-packaged project, pomArtifact and projectArtifact have the same coordinates. The existing code replaced pomArtifact with projectArtifact when projectArtifact had a file — which was the JAR set by jar:jar. This caused install:install to install the JAR under the .pom extension in the local repository.

Root cause

In 3.1.1, this was guarded by if (!"pom".equals(project.getPackaging())). That guard was removed in 3.1.2 (MINSTALL-192) with the intent of "handling it centrally" — but the central handling is the buggy substitution itself.

Fix

Remove the pomArtifact = projectArtifact substitution. pomArtifact is constructed via new ProjectArtifact(project), which wraps project.getFile() — always the POM file, regardless of what other plugins set on project.getArtifact().getFile(). This is the correct artifact to install.

Test

Added IT minstall-315: runs jar:jar install:install on a pom-packaged project and verifies that the installed artifact is valid XML (a POM), not a ZIP (a JAR).

Fixes MINSTALL-315

…en jar:jar runs first

When jar:jar is invoked on a pom-packaged project, it sets project.getArtifact().getFile()
to the produced JAR. In InstallMojo.processProject(), when pomArtifact and projectArtifact
have the same coordinates (pom packaging), the code was replacing pomArtifact with
projectArtifact, which carried the JAR file — causing install:install to install the JAR
instead of the POM.

The fix removes the substitution: pomArtifact (built from ProjectArtifact) already wraps
project.getFile() (the POM file), which is always the correct artifact to install.

Regression test: src/it/minstall-315 runs jar:jar then install:install on a pom-packaged
project and verifies that the installed artifact is XML (POM), not a JAR (ZIP).

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The core fix is correct and well-reasoned. ProjectArtifact(project) calls setFile(project.getFile()) — always the POM file — so removing the pomArtifact = projectArtifact substitution is the right call: pomArtifact never needed to adopt the JAR file set by jar:jar. The equalsId branch is only entered for pom packaging (where G:A:V:E match), so non-pom projects are unaffected.

One nit on verify.groovy.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread src/it/minstall-315/verify.groovy Resolved

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The nit on verify.groovy has been addressed cleanly — the simplified version keeps only the ZIP magic-byte check (PK\u0003\u0004), which is both sufficient and unambiguous for catching the regression. The removed XML-detection block (fragile charset assumption, triple-nested if) was dead weight. Good call.

Core fix in InstallMojo.java is correct. ProjectArtifact(project) wraps project.getFile() — always the POM — so removing the pomArtifact = projectArtifact substitution is safe and minimal. Non-pom projects are unaffected since equalsId is only true when G:A:V:E match (pom packaging only).

Ready to merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@elharo elharo changed the title Fix MINSTALL-315: pom-packaged project installs JAR instead of POM when jar:jar runs first Fix 315: pom-packaged project installs JAR instead of POM when jar:jar runs first Sep 30, 2026
@elharo

elharo commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

There doesn't seem to be an MINSTALL-315 issue. Please check and update.

Tangential note, the consistent misuse of the old JIRA linking syntax to issues that don't exist or that are in github instead of Jira is some of the clearest evidence I've seen lately that the LLMs are cargo culting instead of actually thinking.

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.

4 participants