Skip to content

Commit

Permalink
Refactor Maven artifact processing
Browse files Browse the repository at this point in the history
This now leverages the APIs on MavenNormalizedPublication to make sure
all artifacts are published.
This fixes for example the publication of Gradle Module Metadata,
stable since Gradle 5.3 and produced by default with Gradle 6.0.

Fixes jfrog#247
  • Loading branch information
ljacomet committed Oct 9, 2019
1 parent c1a1e5a commit 413662c
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.gradle.api.publish.ivy.internal.publisher.IvyNormalizedPublication;
import org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity;
import org.gradle.api.publish.maven.MavenArtifact;
import org.gradle.api.publish.maven.MavenArtifactSet;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal;
import org.gradle.api.publish.maven.internal.publisher.MavenNormalizedPublication;
Expand Down Expand Up @@ -246,25 +245,32 @@ public Set<GradleDeployDetails> getArtifactDeployDetails() {
if (builder != null) {
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(
mavenPublication.getArtifactId(), "pom", "pom", null, file);
addMavenArtifactToDeployDetails(deployDetails, publicationName, builder, artifactInfo, mavenPublication);
addMavenArtifactToDeployDetails(deployDetails, publicationName, builder, artifactInfo, mavenNormalizedPublication);
}
}
// Second adding the main artifact of the publication
createPublishArtifactInfoAndAddToDeployDetails(mavenNormalizedPublication.getMainArtifact(), deployDetails, mavenNormalizedPublication, publicationName);

MavenArtifactSet artifacts = mavenPublication.getArtifacts();
// Third adding all additional artifacts - includes Gradle Module Metadata when produced
Set<MavenArtifact> artifacts = mavenNormalizedPublication.getAdditionalArtifacts();
for (MavenArtifact artifact : artifacts) {
File file = artifact.getFile();
DeployDetails.Builder builder = createBuilder(file, publicationName);
if (builder == null) continue;
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(
mavenPublication.getArtifactId(), artifact.getExtension(),
artifact.getExtension(), artifact.getClassifier(),
file);
addMavenArtifactToDeployDetails(deployDetails, publicationName, builder, artifactInfo, mavenPublication);
createPublishArtifactInfoAndAddToDeployDetails(artifact, deployDetails, mavenNormalizedPublication, publicationName);
}
}
return deployDetails;
}

private void createPublishArtifactInfoAndAddToDeployDetails(MavenArtifact artifact, Set<GradleDeployDetails> deployDetails, MavenNormalizedPublication mavenPublication, String publicationName) {
File file = artifact.getFile();
DeployDetails.Builder builder = createBuilder(file, publicationName);
if (builder == null) return;
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(
mavenPublication.getArtifactId(), artifact.getExtension(),
artifact.getExtension(), artifact.getClassifier(),
file);
addMavenArtifactToDeployDetails(deployDetails, publicationName, builder, artifactInfo, mavenPublication);
}

private File getIvyDescriptorFile(IvyNormalizedPublication ivy) {
try {
return ivy.getIvyDescriptorFile();
Expand Down Expand Up @@ -358,7 +364,7 @@ private void addIvyArtifactToDeployDetails(Set<GradleDeployDetails> deployDetail

private void addMavenArtifactToDeployDetails(Set<GradleDeployDetails> deployDetails, String publicationName,
DeployDetails.Builder builder,
PublishArtifactInfo artifactInfo, MavenPublication mavenPublication) {
PublishArtifactInfo artifactInfo, MavenNormalizedPublication mavenPublication) {
Map<String, String> extraTokens = getExtraTokens(artifactInfo);
builder.artifactPath(IvyPatternHelper.substitute(
LayoutPatterns.M2_PATTERN, mavenPublication.getGroupId().replace(".", "/"),
Expand Down

0 comments on commit 413662c

Please sign in to comment.