Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ private ArtifactDeployerRequest createDeployerRequest() {
ProjectManager projectManager = getProjectManager();
Collection<ProducedArtifact> deployables = projectManager.getAllArtifacts(project);
Collection<ProducedArtifact> attachedArtifacts = projectManager.getAttachedArtifacts(project);
List<ProducedArtifact> toDeploy = new ArrayList<>(deployables);

ArtifactManager artifactManager = getArtifactManager();
if (artifactManager.getPath(project.getPomArtifact()).isEmpty()) {
Expand All @@ -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'.");
Expand All @@ -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();

Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProducedArtifact> 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 {
Expand Down
Loading