How to publish multiple artifacts with same artifactId, different classifiers at different times

plugins

(Justin) #1

Hi all,

I’m attempting to publish native artifacts to ArtifactoryOnline without cross-compiling everything in the same job on the same machine. I’m using classifiers to distinguish artifacts amongst our supported platforms, similar to what Maven Nar plugin does. While Jenkins has multi-configuration and multi-job plugins, there will still be independent Gradle tasks run on each machine.

On Windows:

$ ./gradlew publish
Upload https://…artifactoryonline.com/…/libs-snapshots-local/com/foo/bar/1.0.0-SNAPSHOT/bar-1.0.0-20160718.035552-1.pom
Upload https://…artifactoryonline.com/…/libs-snapshots-local/com/foo/bar/1.0.0-SNAPSHOT/bar-1.0.0-20160718.035552-1-headers.zip
Upload https://…artifactoryonline.com/…/libs-snapshots-local/com/foo/bar/1.0.0-SNAPSHOT/bar-1.0.0-20160718.035552-1-win.x64-exports.zip
Upload https://…artifactoryonline.com/…/libs-snapshots-local/com/foo/bar/1.0.0-SNAPSHOT/bar-1.0.0-20160718.035552-1-win.x64.vc14.zip
Upload https://…artifactoryonline.com/…/libs-snapshots-local/com/foo/bar/1.0.0-SNAPSHOT/bar-1.0.0-20160718.035552-1-win.x64.vc14-pdb.zip

On Linux:

$ ./gradlew publish
Upload https://…artifactoryonline.com/…/libs-snapshots-local/com/foo/bar/1.0.0-SNAPSHOT/bar-1.0.0-20160718.035556-8.pom
Upload https://…artifactoryonline.com/…/libs-snapshots-local/com/foo/bar/1.0.0-SNAPSHOT/bar-1.0.0-20160718.035556-8-headers.zip
Upload https://…artifactoryonline.com/…/libs-snapshots-local/com/foo/bar/1.0.0-SNAPSHOT/bar-1.0.0-20160718.035556-8-el6.x64.gcc44.zip

Obviously this overwrites the latest snapshot version for which only one platform has artifacts, e.g. Gradle on Windows no longer finds bar-1.0.0-20160718.035552-1-win.x64.vc14.zip.

I found one forum post that explains how Artifactory batches artifacts together. But I don’t know that either of Gradle’s Maven plugins has the flexibility to allow this, e.g. publish to com/foo/bar/1.0.0-SNAPSHOT but set timestamp in artifact names to join another batch.

Does anyone have a good solution for batching snapshots of artifacts?

Thanks!


(Justin) #2

Amidst the silence, I’ve written a bit to accomplish this. Feel free to share feedback.

buildscript {
repositories {
maven {
name 'Gradle Plugins’
url ‘https://plugins.gradle.org/m2/
}
}
dependencies {
classpath ‘org.jfrog.artifactory.client:artifactory-java-client-services:1.2.2’
}
}

apply plugin: ‘maven-publish’

import org.jfrog.artifactory.client.Artifactory
import org.jfrog.artifactory.client.ArtifactoryClient

gradle.taskGraph.whenReady {
def artifactory = ArtifactoryClient.create(
‘https://…artifactoryonline.com/…/’,
artifactory_user, artifactory_password)
def repository = artifactory.repository(‘libs-snapshots-local’)
publishing.publications.each { Publication pub ->
def snapshotVersion = pub.version.replaceAll(’-SNAPSHOT’, “-${snapshot}”)
def task = project.tasks.findByName(“publish${pub.name}PublicationToMavenRepository”)
task.deleteAllActions()
task.doLast {
def groupPath = pub.groupId.replaceAll(’\.’, ‘/’)
pub.artifacts.each { MavenArtifact artifact ->
def snapshotName = "${pub.artifactId}-${snapshotVersion}-${artifact.classifier}.${artifact.extension}"
println “Upload ${groupPath}/${pub.artifactId}/${pub.version}/${snapshotName}“
repository.upload(”${groupPath}/${pub.artifactId}/${pub.version}/${snapshotName}”, artifact.file)
.doUpload()
}
task = project.tasks.findByName(“generatePomFileFor${pub.name}Publication”)
println “Upload " + “${groupPath}/${pub.artifactId}/${pub.version}/${pub.artifactId}-${snapshotVersion}.pom"
repository.upload(”${groupPath}/${pub.artifactId}/${pub.version}/${pub.artifactId}-${snapshotVersion}.pom”, task.destination)
.doUpload()
}
}
}