How to fetch Nexus repository file into android app

2.1k views Asked by At

I want to define gradle dependencies for the .aar file of my module, which is already uploaded on nexus repository. Now I am trying to declare dependency for the same .aar file into gradle file of my android application, but not able to fetch the .aar file from Nexus repository.

I am using below entry inside build.gradle file of android application:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://MY_COMPANY_DOMAIN/nexus/content/repositories/MY_PROJECT-Releases/'
        }
    }
}

dependencies {
    compile 'GROUP_NAME:FILE_NAME:VERSION_NUMBER'
}

After building my project, I am getting below error:

"Error:Could not find GROUP_NAME:FILE_NAME:VERSION_NUMBER.
Required by:
    PROJECT_NAME:app:unspecified
<a>Search in build.gradle files</a>"

Note: In my case Nexus repository is secure, and we need to use credentials to access that repo. I think, we need to specify authentication data also somewhere inside gradle file. Please suggest me, how can we define authentication section inside gradle to fetch .aar/.jar file from Nexus repo.

Thanks, Sumeet.

1

There are 1 answers

1
ditn On BEST ANSWER

You'll need to add authentication information before you'll be able to sync properly. Create a ~/.gradle/gradle.properties file if it doesn't exist already, and add your credentials like so:

nexusUrl=mycompanydomain
nexusUsername=myusername
nexusPassword=mypassword

Then add these credentials to your repository declataration:

repositories {
    maven {
        url nexusUrl + 'nexus/content/repositories/MY_PROJECT-Releases/'
        credentials(PasswordCredentials) {
            username nexusUsername
            password nexusPassword
        }
    }
}