mrSaraf
mrSaraf

Reputation: 143

Gradle ignores private Nexus repository when searching for dependencies

I am trying to pull some internal dependencies from a private Nexus repository. But when I build the project, gradle does not search for the dependency in the private repo but looks for it in the maven repos.

I did some investigations and found that this is happening with only one project. Dependencies do get pulled in other projects. I still don't know why it is happening.

This is how I have added the repository:

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
    maven { url 'https://jitpack.io' }
    maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda' }
    maven { url 'https://repo.gradle.org/gradle/libs-releases' }

    maven {
        url 'http://private/repository/project'
        credentials {
            username = "user"
            password = "password"
        }
    }
}

dependency:

implementation 'com.project:project-1'

This is what gradle shows:

* What went wrong:
Execution failed for task ':workflows:compileKotlin'.
> Could not resolve all files for configuration ':workflows:compileClasspath'.
   > Could not find project:0.1.
     Searched in the following locations:
       - file:/C:/Users/local/.m2/repository/com/project/directory/0.1-SNAPSHOT/project-1.pom
       - file:/C:/Users/local/.m2/repository/com/project/directory/0.1-SNAPSHOT/project-1.jar
       - https://jcenter.bintray.com/com/project/directory/0.1-SNAPSHOT/project-1.pom
       - https://jcenter.bintray.com/com/project/directory/0.1-SNAPSHOT/project-1.jar
       - https://repo.maven.apache.org/maven2/com/project/directory/0.1-SNAPSHOT/project-1.pom
       - https://repo.maven.apache.org/maven2/com/project/directory/0.1-SNAPSHOT/project-1.jar
       - https://software.r3.com/artifactory/corda/com/project/directory/0.1-SNAPSHOT/project-1.pom
       - https://software.r3.com/artifactory/corda/com/project/directory/0.1-SNAPSHOT/project-1.jar
       - https://jitpack.io/com/project/directory/0.1-SNAPSHOT/project-1.pom
       - https://jitpack.io/com/project/directory/0.1-SNAPSHOT/project-1.jar

It does not search in the private repository.

Upvotes: 1

Views: 3441

Answers (2)

lomec
lomec

Reputation: 1354

As an updated information and solution for me was in the settings.gradle

There is another repositories block in dependencyResolutionManagement.

Upvotes: 0

mrSaraf
mrSaraf

Reputation: 143

The project I was working with had two gradle files, repositories.gradle & build.gradle

I was adding the nexus URL to repositories.gradle file in the repositories block. But the URL was not being searched for dependencies. After a bit of exploration I found that the build.gradle file also has a repositories block:

allProjects {

    . . . . . . . . . . 

    repositories {
        . . . . . . . . . . 
        . . . . . . . . . . 
    }
}

This seems to be overriding the repositories block in repositories.gradle file. When I added the nexus URL in here the dependencies were resolved.

Hope that helps anyone having a similar issue :)

Upvotes: 4

Related Questions