How can you upload to an Artifactory with a Gradle Task?

Hello, I am using the Artifactory Publish Task from ‘http://wiki.jfrog.org/confluence/display/RTF/Working+with+Gradle’ (and am using gadle-milestone 3) I am starting my Build Script with: gradle -DPassword=password -DUser=mike uploadArchives

But I always get the error: … User anonymous is not permitted to deploy … Here’s a fragment of my Code:

repositories {

println "User: "+ System.properties[“User”]

println "PW:

" + System.properties[“Password”]

org.apache.ivy.util.url.CredentialsStore.INSTANCE.addCredentials(‘plugins-snapshot’, System.properties[“User”], System.properties[“User”],System.properties[“Password”]);

mavenRepo urls: “http://artifactoryURL/artifactory/experimental”; }

uploadArchives {

repositories {

mavenRepo urls: “http://artifactoryURL/artifactory/experimental”;

repositories.mavenDeployer {

repository(url: “http://artifactoryURL.com/artifactory/experimental”) {

authentication(userName: System.properties[“User”], password: System.properties[“Password”])

println "User: "+ System.properties[“User”]

println "PW:

" + System.properties[“Password”]

}

pom.version = versionNumber

pom.artifactId = artifactId

pom.groupId = groupId

}

} }

However if I print my properties they are not null. I tried a gradle.properties file but I get the same error over and over again… I also tried the Artifactory Plugin and it worked just fine, but now I need a simple task to do it, which can be used in external Build Scripts.

I’m quite new to Gradle, so maybe this is a very stupid question, but I’d appreciate any help. Thank You very much in advance!

Hi Mike, I think the repository closure in your uploadArchives task is not necessary. try this snippet:

uploadArchives {
  repositories.mavenDeployer {
    repository(url: "your repo url") {
     authentication(userName: System.properties["User"], password: System.properties["Password"])
    }
   }
  }

regards, René

The easiest way is to use the Artifactory plugin (http://wiki.jfrog.org/confluence/display/RTF/Gradle+Artifactory+Plugin). The plugin auto-adds an ‘artifactoryPublish’ task which you can call.

Yoav

Thank you very much for the help it worked just fine!

Your link includes the closing bracket. Can you fix it?

Seems like I cannot edit the original answer at this point. Anyways, here’s the good link: http://wiki.jfrog.org/confluence/display/RTF/Gradle+Artifactory+Plugin