3
votes

I'm using the gradle artifactory publish plugin documented here: http://www.jfrog.com/confluence/display/RTF/Gradle+1.6+Publishing+Artifactory+Plugin

I'm using the standard config exactly as laid out in the documentation.

When I run the gradle publishArtifactory task from the command line I get output like this. I.e. It deploys to my correct module name.

Deploying artifact: http://<my server>/artifactory/libs-snapshot-local/<my actual module name>/web/0.1-SNAPSHOT/web-0.1-SNAPSHOT.war

When I configure Jenkins to run the gradle publishArtifactory task using the same gradle build file I get output like this. I.e. It uses the Jenkins build for the module name.

Deploying artifact: http://artifactory01.bcinfra.net:8081/artifactory/libs-snapshot-local/<the name of the jenkins build>/web/0.1-SNAPSHOT/web-0.1-SNAPSHOT.war

Any ideas on how to prevent the artifactory plugin from using the Jenkins build name for the module name?

2

2 Answers

9
votes

The module name used for uploading is derived from the gradle project name. The default value for a gradle project name is taken from the project folder name. I suspect that on your jenkins job you check out your code into a folder named like your build job. That's why per default this folder name is used as project name.

The cleanest solution is to explicitly set your project name in gradle.

Therefore you need a settings.gradle file in your project root folder that contains the project name:

rootProject.name = "web" 
3
votes

You can also let Gradle single-handedly do the publishing to Artifactory, without the need for the Artifactory plugin in Jenkins.

This way, you can set the names of the artifacts using artifactId "your artifact name" without changing the project's name as suggested by Rene Groeschke.

Here's my publish.gradle that demonstrates this:

buildscript {
  repositories {
    jcenter() 
  }
  dependencies {
    classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
  }
}
// Because this is a helper script that's sourced in from a build.gradle, we can't use the ID of external plugins
// We either use the full class name of the plugin without quotes or an init script: http://www.gradle.org/docs/current/userguide/init_scripts.html
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPublicationsPlugin

// Pack the sources into a jar
task sourceJar(type: Jar) {
  from sourceSets.main.allSource; classifier = "sources" 
}

// Pack the Javadoc into a jar
task javadocJar(type: Jar) {
  from javadoc.outputs.files; classifier = "javadoc" 
}

apply plugin: "maven-publish"

publishing {
  publications {
    mavenJava(MavenPublication){
      from components.java

      // Set the base name of the artifacts
      artifactId "your artifact name"

      artifact jar
      artifact sourceJar
      artifact javadocJar
    }
  }
}

artifactory {
  contextUrl = "http://localhost:8081/artifactory"

    publish {
      // Publish these artifacts
      defaults{ publications ("mavenJava") }

      repository {
        repoKey = "libs-release-local"
        // Provide credentials like this:
        //-Partifactory.publish.password=yourPassword
        //-Partifactory.publish.username=yourUsername
      }
    }
  resolve {
    repository {
      repoKey = "libs-release"
    }
  }
}

You can use this script in your build.gradle via apply from: "path/to/publish.gradle" and call it like this:

./gradlew artifactoryPublish -Partifactory.publish.username="yourUsername" -Partifactory.publish.password="yourPassword"