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 3bd0627..113b145 100644 --- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java +++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java @@ -423,6 +423,7 @@ private ArtifactDeployerRequest createDeployerRequest() { ProjectManager projectManager = getProjectManager(); Collection deployables = projectManager.getAllArtifacts(project); Collection attachedArtifacts = projectManager.getAttachedArtifacts(project); + List toDeploy = new ArrayList<>(deployables); ArtifactManager artifactManager = getArtifactManager(); if (artifactManager.getPath(project.getPomArtifact()).isEmpty()) { @@ -448,13 +449,14 @@ private ArtifactDeployerRequest createDeployerRequest() { "The packaging for this project did not assign a file to the build artifact"); } else { if (allowIncompleteProjects) { - getLog().warn(""); - getLog().warn("The packaging plugin for this project did not assign"); - getLog().warn( - "a main file to the project but it has attachments. Change packaging to 'pom'."); - getLog().warn(""); - getLog().warn("Incomplete projects like this will fail in future Maven versions!"); - getLog().warn(""); + // The main artifact has no file: its path is e.g. the output directory of a module + // source hierarchy, where the JAR plugin attaches one JAR per Java module instead of + // assigning a single main JAR. Deploy the POM and the attachments only; do not hand + // the directory to the deployer, which would otherwise fail with "is a folder". + getLog().info("The project's main artifact has no file" + + " (e.g. a module source hierarchy produces one artifact per Java module);" + + " deploying the POM and the attached artifacts only."); + toDeploy.remove(deployable); } else { throw new MojoException("The packaging plugin for this project did not assign " + "a main file to the project but it has attachments. Change packaging to 'pom'."); @@ -470,7 +472,7 @@ private ArtifactDeployerRequest createDeployerRequest() { ArtifactDeployerRequest request = ArtifactDeployerRequest.builder() .session(session) .repository(getDeploymentRepository(session.isVersionSnapshot(project.getVersion()))) - .artifacts(deployables) + .artifacts(toDeploy) .retryFailedDeploymentCount(Math.max(1, Math.min(10, getRetryFailedDeploymentCount()))) .build(); 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 58175e6..bd31ca9 100644 --- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java @@ -185,6 +185,33 @@ void deployWithAttachedArtifacts(DeployMojo mojo) throws Exception { request.getRepository().getUrl()); } + @Test + @InjectMojo(goal = "deploy") + @MojoParameter(name = "deployAtEnd", value = "false") + @MojoParameter(name = "allowIncompleteProjects", value = "true") + void mainArtifactWithDirectoryPathIsSkippedWhenAttachmentsExist(DeployMojo mojo) throws Exception { + // Module source hierarchy: the JAR plugin attaches one JAR per Java module and never assigns a + // file to the main artifact, whose path stays the (directory) build output. Deploy must deploy the + // POM + attachments and must NOT hand the directory to the deployer (which fails with "is a folder"). + assertNotNull(mojo); + Project project = (Project) getVariableValueFromObject(mojo, "project"); + projectManager.attachArtifact( + project, + new ProducedArtifactStub("org.apache.maven.test", "foo.bar", "", "1.0-SNAPSHOT", "jar"), + Paths.get(getBasedir(), "target/test-classes/unit/attached-artifact-test-1.0-SNAPSHOT.jar")); + artifactManager.setPath(project.getMainArtifact().get(), Paths.get(getBasedir(), "target/test-classes/unit")); + + ArtifactDeployerRequest request = execute(mojo); + + assertNotNull(request); + Collection artifacts = request.getArtifacts(); + assertEquals( + Arrays.asList( + "org.apache.maven.test:maven-deploy-test:pom:1.0-SNAPSHOT", + "org.apache.maven.test:foo.bar:jar:1.0-SNAPSHOT"), + artifacts.stream().map(Artifact::key).collect(Collectors.toList())); + } + @Test @InjectMojo(goal = "deploy") void legacyAltDeploymentRepositoryWithDefaultLayout(DeployMojo mojo) throws Exception {