Jason
Jason

Reputation: 2492

Issues pulling artifacts or dependencies using Gradle from artifactory

So, here is what I want to do:

  1. push a library to artifactory using gradle -> Done
  2. get the service to pull the dependent library from artifactory -> Issues

From what I understand it can be done using Gradle Artifactory Plugin.

Below is the sample build.gradle :

buildscript {
    repositories {
             jcenter()
        }

    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.1.0'
    }
}


apply plugin: "com.jfrog.artifactory"
apply plugin: 'eclipse'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'

group = 'a.b.c'

allprojects {
    apply plugin: 'artifactory'
}

configurations{
...
}

dependencies {
    compile group: 'a', name: 'b', version:'c'
    compile group: 'x', name: 'y', version:'z'
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'gradle-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            ivy {
                ivyLayout = '[organization]/[module]/ivy-[revision].xml'
                artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
                mavenCompatible = false
            }
        }
    }
    resolve {
        repository {
            repoKey = 'gradle'
            repoKey = 'gradle-release-local'
            maven = true

        }
    }
}

Sample Settings.gradle

rootProject.name = ‘partnering'
includeFlat ‘a'
project(‘:a').projectDir=new File(settings,'../a')

Note:

In dependencies, as you can see

  1. compile group: 'a', name: 'b', version:'c' This needs repoKey = gradle-release-local
  2. compile group: 'x', name: 'y', version:'z' This needs repoKey = grade

ERROR:

  1. Cannot resolve external dependency a.b.c because no repositories are defined.
  2. However I can see the library is already present in artifactory

Can somebody please let me with this issue.

Upvotes: 0

Views: 1275

Answers (2)

JBaruch
JBaruch

Reputation: 22893

gradle is a virtual repository, it aggregates number of other repositories in it.

In the repositories configuration, make sure that gradle virtual repository contains the gradle-release-local repository.

Once done, only leave one repoKey for resolution, gradle.

Upvotes: 1

schrieveslaach
schrieveslaach

Reputation: 1819

When you want to pull dependencies from a remote repository, you need to define them in build.gradle. Pushing libraries to a repository is isolated from pulling libraries.

The following example contains two examples. One for maven central and and one for a custom repository.

repositories {
    mavenCentral()
    maven {
        url "http://www.edwardraff.com/maven-repo/"
    }
}

Look into the documentation.

Upvotes: 0

Related Questions