Skip to content

Commit

Permalink
Fix bomClassifier used as type, deploy the artifact with the specifie…
Browse files Browse the repository at this point in the history
…d groupId/artifactId
  • Loading branch information
gnodet committed Oct 17, 2024
1 parent 09f2669 commit 96a7631
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Objects;
import java.util.Properties;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Exclusion;
Expand Down Expand Up @@ -164,7 +166,10 @@ public void execute() throws MojoExecutionException {
File outputFile = new File(mavenProject.getBuild().getDirectory(), outputFilename);
modelWriter.writeModel(model, outputFile);
if (attach) {
mavenProjectHelper.attachArtifact(mavenProject, bomClassifier, outputFile);
DefaultArtifact artifact = new DefaultArtifact(
bomGroupId, bomArtifactId, bomVersion, null, "pom", bomClassifier, new PomArtifactHandler());
artifact.setFile(outputFile);
mavenProject.addAttachedArtifact(artifact);
}
}

Expand Down Expand Up @@ -306,4 +311,36 @@ void writeModel(Model pomModel, File outputFile) throws MojoExecutionException {
}
}
}

static class PomArtifactHandler implements ArtifactHandler {
PomArtifactHandler() {}

public String getClassifier() {
return null;
}

public String getDirectory() {
return null;
}

public String getExtension() {
return "pom";
}

public String getLanguage() {
return "none";
}

public String getPackaging() {
return "pom";
}

public boolean isAddedToClasspath() {
return false;
}

public boolean isIncludesDependencies() {
return false;
}
}
}

0 comments on commit 96a7631

Please sign in to comment.