gradle can't resolve nexus dependency

2019-08-27 20:36发布

问题:

I have a dependency I'd like to include from a local nexus. I've seen several related problems that all say to do something like

apply plugin: "java"
apply plugin: "maven"

repositories {
    maven {
        url "http://my.url.com/"
    }
}

dependencies {  
    compile "name:id:version"
}

I can access the nexus fine via web but when I try the above, I end up with a error message

Could not resolve: name:id:version

Any help would be greatly appreciated.

回答1:

I found my problem. There were transitive dependencies I didn't catch as I was initially building from Eclipse without the --stacktrace option. I modified the build script such that

compile("name:id:version") {
    exclude group: "another-name", module: "its-module"
    // other dependencies to exclude ...
}


回答2:

If by local repository you mean your local computer repository, then to ask Gradle to lookup dependencies from the local maven repository you should explicitly tell him to do so like this:

repositories {
  mavenLocal()
}

Gradle is not like maven and is not using the local repository of the maven to cache downloaded artifacts. From the Gradle points of view, the local maven repository is also like other repositories.