Uploaded image for project: 'Jenkins Artifactory Plug-in'
  1. Jenkins Artifactory Plug-in
  2. HAP-881

Resolver is not used to resolve Gradle buildscript dependencies



    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 2.8.2
    • Fix Version/s: None
    • Component/s: Gradle
    • Labels:
    • Environment:

      Windows 8.1
      Jenkins 2.40
      Gradle 3.3 & 2.2


      To build an android project I have to add the "com.android.tools.build:gradle:2.0.0" dependency to the buildscript to make android task available.

      buildscript {
          dependencies {
              classpath 'com.android.tools.build:gradle:2.0.0'

      I added our corporate repository to buildscript section in USER_HOME\.gradle\init.gradle like this:

      allprojects {
          // Configures repository to resolve buildscript dependencies.
          // This section is needed by build tasks to work properly, resolve plugins, etc.
          buildscript {
              repositories {
                  maven {
                      url "${System.properties['artifactory_contextUrl']}/mvn-libs-all"
                      credentials {
                          username = "${System.properties['artifactory_user']}"
                          password = "${System.properties['artifactory_password']}"
          // Configures repository to resolve project dependencies.
          // This section is needed in order to compile project sources.
          // Copies settings from buildscript to reduce redundancy.
          rootProject.buildscript.repositories.each {

      Building the project from the command line everything works fine.

      Problems arise however, when I want to build in Jenkins, using Jenkins Artifactory Plugin. Either using a conventional Freestyle job, or a Pipeline one. In both cases the build fails telling

      [Pipeline] ArtifactoryGradleBuild
      [gradle-android-aar] $ cmd.exe /C "c:\Portable\gradle-3.3\bin\gradle.bat --init-script C:/Users/lkp/AppData/Local/Temp/init-artifactory6209881413559766967gradle clean artifactoryPublish -b build.gradle && exit %%ERRORLEVEL%%"
      Starting a Gradle Daemon (subsequent builds will be faster)
      FAILURE: Build failed with an exception.
      * What went wrong:
      A problem occurred configuring root project 'gradle-android-aar'.
      > Could not resolve all dependencies for configuration ':classpath'.
         > Cannot resolve external dependency com.android.tools.build:gradle:2.0.0 because no repositories are defined.
           Required by:
               project :
      * Try:
      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

      When building a simple job which uses no buildscript level dependencies it builds successfully using the exact same configuration. Given that project level dependencies are resolved correctly while buildscript level ones are not suggests me that resolver configuration in Jenkins Artifactory Plugin is not passed to buildscript level, only to project level.

      Below is my Pipeline script.

      stage("Checkout") {
          node {
              // checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'WipeWorkspace']], submoduleCfg: [], userRemoteConfigs: [[url: 'file:///c:/workspace/stash-dev/psbx/gradle-android-aar']]]
              checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, submoduleCfg: [], userRemoteConfigs: [[url: 'file:///c:/workspace/stash-dev/psbx/gradle-android-aar']]]
      stage("Build") {
          node {
              def server = Artifactory.server 'artifactory-loc'
              def rtGradle = Artifactory.newGradleBuild()
              rtGradle.resolver server: server, repo: 'mvn-libs-all'
              rtGradle.deployer server: server, repo: 'mvn-local'
              rtGradle.tool = 'Gradle 3.3'
              rtGradle.useWrapper = false
              withEnv(["JAVA_HOME=${tool 'JDK 1.8'}"]) {
                  // buildinfo is created manually in order to toggle env.capture flag, build info is merged in by rtMaven.run
                  def buildInfo = Artifactory.newBuildInfo()
                  buildInfo.env.capture = true
                  buildInfo = rtGradle.run buildFile: 'build.gradle', tasks: 'clean artifactoryPublish', buildInfo: buildInfo, switches: '--info'
                  server.publishBuildInfo buildInfo




            eyalbe Eyal Ben David
            peter.lauko Peter Lauko
            0 Vote for this issue
            1 Start watching this issue