This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 6253838 Deploy the POM, not the JAR, for pom-packaged projects after
jar:jar
6253838 is described below
commit 625383880d17a95c6cbf90bed6a15f15c7140dfa
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Nov 21 17:32:06 2026 +0100
Deploy the POM, not the JAR, for pom-packaged projects after jar:jar
Do not reintroduce the projectArtifact substitution for same-coordinate
artifacts: it deploys whatever file a packaging plugin set (a JAR) as the .pom.
Same fix as maven-install-plugin#457.
---
.../apache/maven/plugins/deploy/DeployMojo.java | 8 +++---
.../maven/plugins/deploy/DeployMojoTest.java | 31 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index 0d9f03d..3dadc0d 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -368,11 +368,11 @@ public class DeployMojo extends AbstractDeployMojo {
// incomplete project: is not pom project and projectArtifact has no
file
// we must compare coordinates ONLY (as projectArtifact may not have
file, and Artifact.equals factors it in)
- // BUT if projectArtifact has file set, use that one
+ // For pom-packaged projects, pomArtifact and projectArtifact have the
same coordinates: they represent the
+ // same artifact. In that case, another plugin (e.g. jar:jar) may have
set a non-POM file on
+ // project.getArtifact() (#203). We must NOT use that file:
pomArtifact already wraps
+ // project.getFile() (the actual POM) via ProjectArtifact, which is
the correct artifact to deploy.
if (ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)) {
- if (isFile(projectArtifact.getFile())) {
- pomArtifact = projectArtifact;
- }
projectArtifact = null;
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index a9ad11b..33b0155 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -22,6 +22,7 @@ import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -30,6 +31,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
import org.apache.maven.api.plugin.testing.Basedir;
import org.apache.maven.api.plugin.testing.InjectMojo;
@@ -49,6 +52,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static
org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -529,6 +533,33 @@ class DeployMojoTest {
assertFalse(new File(remoteRepo, GA_PATH +
"1.0/maven-deploy-test-1.0.jar").exists());
}
+ /**
+ * {@code jar:jar} on a pom-packaged project sets the JAR as the file of
{@code project.getArtifact()}; deploy must
+ * still upload the POM under the {@code .pom} name (#203).
+ */
+ @Test
+ @InjectMojo(goal = "deploy")
+ void testDeployPomProjectAfterJarJarDeploysPom(DeployMojo mojo) throws
Exception {
+ mojo.setPluginContext(new ConcurrentHashMap<>());
+ mavenProject.setVersion("1.0");
+ setProjectArtifact(mavenProject, "pom");
+ mavenProject.setPackaging("pom");
+ Path jar = tempDir.resolve("maven-deploy-test-1.0.jar");
+ try (ZipOutputStream zip = new
ZipOutputStream(Files.newOutputStream(jar))) {
+ zip.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
+ zip.write("Manifest-Version:
1.0\n".getBytes(StandardCharsets.UTF_8));
+ zip.closeEntry();
+ }
+ mavenProject.getArtifact().setFile(jar.toFile());
+
+ mojo.execute();
+
+ Path deployedPom = remoteRepo.toPath().resolve(GA_PATH +
"1.0/maven-deploy-test-1.0.pom");
+ assertTrue(Files.isRegularFile(deployedPom), "missing " + deployedPom);
+ assertArrayEquals(Files.readAllBytes(mavenProject.getFile().toPath()),
Files.readAllBytes(deployedPom));
+ assertFalse(new File(remoteRepo, GA_PATH +
"1.0/maven-deploy-test-1.0.jar").exists());
+ }
+
@Test
@InjectMojo(goal = "deploy")
void testDeployReleaseWithAttachedArtifact(DeployMojo mojo) throws
Exception {