Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Dependency from Artifactory using Gradle

I have an artifact that has been published to my local Artifactory repository and now I am trying to pull that artifact into a project with gradle.

However, I keep getting the following error:

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.company.app:myapplication:1.0.0.
     Searched in the following locations:
     https://jcenter.bintray.com/com/company/app/...pom
     https://jcenter.bintray.com/com/company/app/...jar

     file:/Users/user/Library/Android/sdk/extras/android/m2repository/com/company/app...pom
     file:/Users/user/Library/Android/sdk/extras/android/m2repository/com/company/app...jar
     file:/Users/user/Library/Android/sdk/extras/google/m2repository/com/company/app...pom
     file:/Users/user/Library/Android/sdk/extras/google/m2repository/com/company/app....jar

This error suggests that it's not even looking at the local artifactory repository. Below are my build.gradle files


Project Level build.gradle

buildscript {
    repositories {
        jcenter()
        maven {
            url '${artifactory_contextUrl}/libs-release-local'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.0"
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

App Level build.gradle

allprojects{
    apply plugin: "com.jfrog.artifactory"
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.company.app:myapplication:1.0.0'
}
like image 805
bcorso Avatar asked Mar 17 '23 00:03

bcorso


1 Answers

The issue was

  1. The maven url needs to be outside of the buildscript
  2. The maven url needs to be in the App level, not Project level build.gradle

Below are my current build.gradle files that work:

Project Level build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

App Level build.gradle

repositories {
    maven {
        url '${artifactory_contextUrl}/libs-release-local'
        credentials {
            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.company.app:myapplication:1.0.0'
}

NOTE: I removed the jfrog plugin because it's only needed if you are publishing to Artifactory.

like image 56
bcorso Avatar answered Mar 21 '23 14:03

bcorso