Artifactory plugin in Gradle

I am trying to use artifactory in gradle.

this is my build.gradle (which was generated from the UI in the artifactory website) :

buildscript {
    repositories {
        maven {
            url 'http://avra_artifactory:8081/artifactory/plugins-release'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }

    }
    dependencies {
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
    }
}

allprojects {
    apply plugin: 'artifactory'
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'libs-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
    }
    resolve {
        repository {
            repoKey = 'libs-release'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
    }
}

but i for some reason get this error:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'GradleConfiguration'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve org.jfrog.buildinfo:build-info-extractor-gradle:2.0.9.
     Required by:
         :GradleConfiguration:unspecified
      > Target host must not be null, or set in parameters.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

GradleConfiguration is the name of the project which the build.gradle resides.

Can someone explain why i get this error?

My personal oppinion is that (depending on what you want to accomplish of cause) you are better off using the gradle buildt in stuff for this.

This section:

resolve {
        repository {
            repoKey = 'libs-release'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
}

Is just dependecy resolving and translates into:

repositories {
    maven url: "artifactory_url"+"/someRepo"
}

And this:

publish {
        repository {
            repoKey = 'libs-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
        }
}

Would work like:

apply plugin: 'maven-publish'
publishing {
 publications {
   mavenJava(MavenPublication) {
   from addToProject.components.java
   artifact addToProject.sourceJar {
     classifier "sources"
   }
   artifact addToProject.javadocJar {
     classifier "javadoc"
   }
 }
}
repositories {
  maven {
    url "some_url"
    credentials {
      username "user"
      password "pass"
    }
  }
}

This is “less strings attached”. But I don’t know your usecase.

I just want to use artifactory to get the jars. i have 4 jars that i want to stay at the server and will be downloaded when needed.

The code you wrote is the same thing?

Then:

apply plugin: 'java'

repositories {
    maven url: "artifactory_url"+"/someRepo"
}

Will most likely do it for you :smile:

i still get java.lang.IllegalStateException: Target host must not be null, or set in parameters. :frowning:

The host was blocked by a firewall, now its fixed !!

Firewalls, gotta love them :slight_smile: