From 413662c1e40e532ed336c6627a3f5feca375e9f1 Mon Sep 17 00:00:00 2001 From: Louis Jacomet Date: Wed, 9 Oct 2019 10:54:39 +0200 Subject: [PATCH] Refactor Maven artifact processing 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 #247 --- .../task/helper/TaskHelperPublications.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/helper/TaskHelperPublications.java b/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/helper/TaskHelperPublications.java index 84dbda903..33da2fa24 100644 --- a/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/helper/TaskHelperPublications.java +++ b/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/helper/TaskHelperPublications.java @@ -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; @@ -246,25 +245,32 @@ public Set 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 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 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(); @@ -358,7 +364,7 @@ private void addIvyArtifactToDeployDetails(Set deployDetail private void addMavenArtifactToDeployDetails(Set deployDetails, String publicationName, DeployDetails.Builder builder, - PublishArtifactInfo artifactInfo, MavenPublication mavenPublication) { + PublishArtifactInfo artifactInfo, MavenNormalizedPublication mavenPublication) { Map extraTokens = getExtraTokens(artifactInfo); builder.artifactPath(IvyPatternHelper.substitute( LayoutPatterns.M2_PATTERN, mavenPublication.getGroupId().replace(".", "/"),