Accessing Dependency from Artifactory using Gradle

bcorso

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'
}
bcorso

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

spring dependency-management gradle plugin with artifactory

Upload artifact to Artifactory using Gradle

Technique to fix Maven Dependency when using Artifactory

User is not permitted to deploy '.json' into Artifactory Using Gradle

How to trigger Artifactory build retention from gradle

Gradle with artifactory

Accessing gradle resources from Java

Unable to find dependency using Gradle

Exclude Package From Gradle Dependency

Exclude project from a dependency in Gradle

WPF Accessing dependency property from code

Dependency missing from the artifactory. How to find which pom requires it?

Module dependency vs artifactory

How to access a maven repo on artifactory in gradle using API key?

Gradle Artifactory Plugin - How to publish artifacts from multiple modules in a project?

Why is Artifactory returning a 403 for all users when called from gradle artifactory plugin?

How to overwrite version of transitive dependency Groovy from Thymeleaf 1.5.8.RELEASE in Spring Boot using Gradle

What is the difference of using "implementation platform(..." instead of dependencyManagement from io.spring.dependency-management gradle plugin

Gradle dependency conflict when using `implementation`

Add provided dependency to test classpath using Gradle

Could not import a dependency in Kotlin project using Gradle

How to use implementation dependency from dependency in dependent Gradle project?

Gradle - understand where a dependency comes from

How to get .AAR file from gradle dependency?

Building a jar file from a gradle dependency

Gradle : How to run tests from a module dependency?

Gradle Dependency resolution changes from 4.10.3 to 6.1.1

Gradle: Add dependency from Java to Native compilation

How to exclude a dependency from built JAR in Gradle?