From 5353d54ef38eecd7ee482fafdce9e81e95e3d5b7 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 11:40:25 +0100 Subject: [PATCH] Remove baked in packaging from plugin --- .../maven/plugins/deploy/DeployMojo.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 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 c9b0d4a4..f8841b79 100644 --- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java +++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java @@ -38,8 +38,10 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.ProjectArtifact; +import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.deployment.DeployRequest; import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.util.artifact.ArtifactIdUtils; /** * Deploys an artifact to remote repository. @@ -285,17 +287,32 @@ private boolean hasExecution(Plugin plugin) { } private void processProject(final MavenProject project, DeployRequest request) throws MojoExecutionException { + // always exists, as project exists + Artifact pomArtifact = RepositoryUtils.toArtifact(new ProjectArtifact(project)); + // always exists, but at "init" is w/o file (packaging plugin assigns file to this when packaged) + Artifact projectArtifact = RepositoryUtils.toArtifact(project.getArtifact()); + + // pom project: pomArtifact and projectArtifact are SAME + // jar project: pomArtifact and projectArtifact are DIFFERENT + // 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) + boolean pomArtifactIsMainArtifact = ArtifactIdUtils.equalsId(pomArtifact, projectArtifact); + if (pomArtifactIsMainArtifact) { + projectArtifact = null; + } + // is not packaged, is "incomplete" + boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile()); - if (isFile(project.getFile())) { - request.addArtifact(RepositoryUtils.toArtifact(new ProjectArtifact(project))); + if (isFile(pomArtifact.getFile())) { + request.addArtifact(pomArtifact); } else { throw new MojoExecutionException("The project POM could not be attached"); } - if (!"pom".equals(project.getPackaging())) { - org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact(); - if (isFile(mavenMainArtifact.getFile())) { - request.addArtifact(RepositoryUtils.toArtifact(mavenMainArtifact)); + if (projectArtifact != null) { + if (!isIncomplete) { + request.addArtifact(projectArtifact); } else if (!project.getAttachedArtifacts().isEmpty()) { if (allowIncompleteProjects) { getLog().warn("");