Reputation: 1188
I am trying to download an artifact from one Nexus repository and upload it to another using Gradle.
My Gradle build file is as follows:
dependencies {
compile group: ARTIFACT_GROUP_ID, name: ARTIFACT_ARTIFACT_ID, version: ARTIFACT_VERSION
}
// Get dependency Artifact file
task upload_artifact(type: Jar){
from(file(project.configurations.compile.find { it.name.startsWith(ARTIFACT_ARTIFACT_ID+"-"+ARTIFACT_VERSION) }))
}
// Finally publish the artifact
publishing {
repositories{
maven{
url NEXUS_URL
credentials {
username NEXUS_USER
password NEXUS_PASSWORD
}
}
}
publications {
maven_artifact(MavenPublication) {
//GAV Co-ordinates to use to publish the artifact
artifact upload_artifact
groupId ARTIFACT_GROUP_ID
artifactId ARTIFACT_ARTIFACT_ID
version ARTIFACT_UPLOAD_VERSION
}
}
}
The Upload works, it uploads a Jar with the correct group, artifact id and version. It also uploads it to the correct location.
PROBLEM:
The uploaded jar is an archive containing the actual jar to be uploaded.
For example if I want to download artifact.jar
and upload it to another nexus repository, the script uploads an artifact.jar
to the correct nexus repository, but if I download the uploaded artifact.jar
and open the archive, I find the downloaded artifact.jar
within it.
Upvotes: 2
Views: 1865
Reputation: 36743
I've since extended this solution to include all artifacts
apply plugin: 'java'
apply plugin: 'maven-publish'
dependencies {
runtime 'log4j:log4j:1.2.17'
runtime 'junit:junit:4.12'
}
repositories {
flatDir {
dirs project.projectDir
}
}
publishing {
repositories {
maven {
url 'http://example.org/nexus/content/repositories/foo-releases'
credentials {
username 'username'
password 'password'
}
}
}
configurations.runtime.allDependencies.each {
def dep = it
def file = file(configurations.runtime.find { it.name.startsWith("${dep.name}-${dep.version}") })
publications.create(it.name, MavenPublication, {
artifact file
groupId dep.group
artifactId dep.name
version dep.version
})
}
}
Upvotes: 1
Reputation: 1188
I got this fixed. The updated script is as follows:
dependencies {
compile group: ARTIFACT_GROUP_ID, name: ARTIFACT_ARTIFACT_ID, version: ARTIFACT_VERSION
}
// Finally publish the artifact
publishing {
repositories{
maven{
url NEXUS_URL
credentials {
username NEXUS_USER
password NEXUS_PASSWORD
}
}
}
publications {
maven_artifact(MavenPublication) {
//GAV Co-ordinates to use to publish the artifact
artifact file(project.configurations.compile.find { it.name.startsWith(ARTIFACT_ARTIFACT_ID+"-"+ARTIFACT_VERSION) })
groupId ARTIFACT_GROUP_ID
artifactId ARTIFACT_ARTIFACT_ID
version ARTIFACT_UPLOAD_VERSION
}
}
}
Instead of using the "upload_artifact" task to specify the artifact being uploaded, I directly passed the file as a parameter to the artifact
method of the maven_artifact
task.
Upvotes: 0