Gradle Artifactory plugin artifact resolution not

2019-09-04 10:29发布

问题:

I am trying to get the Gradle Artifactory Plugin to resolve artifacts.

My build.gradle file is below with the being replaced with the correct hostname

buildscript {
    repositories {
        maven { url 'http://jcenter.bintray.com' }
    }
    dependencies {
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1')
    }
}

apply plugin: 'com.jfrog.artifactory'

artifactory {
   contextUrl = 'http://<URL>:8081/artifactory'   //The base Artifactory URL if not overridden by the publisher/resolver

   resolve {
      repository {
         repoKey = 'training'
         maven = true
      }
   }
}

configurations {
   deploy 
}

dependencies {
   deploy group: 'test', name: 'PolicyAdmin', version: '1.0', ext: 'ear'
}

task downloadFile {
    def fileExec = configurations.deploy.getSingleFile()
}

However when this is run it fails to resolve the artifact. The dependency line was generated from Artifactory.

I am intending to use the "old" publish mechanism. My Gradle version is 2.0.

I have tried an artifactory repository with a maven2-default and a gradle layout.

The stack trace can be found at http://textuploader.com/oljd

The debug trace can be found at http://filebin.ca/1ecmeQ7zYEIU/debug.txt

If I instead use a maven repository i.e.

repositories {
   maven {
      url 'http://<URL>:8081/artifactory/repo'
   } 
}

Then the artifact will resolve I'm therefore either doing something wrong with the artifactory DSL code or there is a bug in the plugin

I have also now tried on Gradle 1.12 and Gradle 2.1 too with the same outcome.

回答1:

I think I found the cause of the issue you're describing. The Gradle Artifactory Plugin seems to function as expected. When executing the "artifactoryPublish" task, the the resolution is done from Artifactory as expected. I also tried adding to my build.gradle the task (downloadFile), dependency configuration (deploy) and the dependency (as in your script):

configurations {
   deploy 
}

dependencies {
   deploy group: 'test', name: 'PolicyAdmin', version: '1.0', ext: 'ear'
}

task downloadFile {
   def fileExec = configurations.deploy.getSingleFile()
}

When invoking the downloadFile task directly as it is defined above, the artifact will indeed not be resolved from Artifactory (unless of course you add that Artifactory as a repository). If however you add << to the task declaration:

task downloadFile << {
   def fileExec = configurations.deploy.getSingleFile()
}

Gradle will attempt to resolve the Artifact from Artifactory. Adding "<<" to the task is equivalent to Task.doLast() as described in Gradle's documentation: http://www.gradle.org/docs/current/dsl/org.gradle.api.Task.html

All of the above seems to consistent with Gradle 2.x (with version 3.0.1 of the plugin), as well as Gradle 1.x (with all versions of the plugin).