Why I am getting a ModuleVersionNotFoundException when using a custom repository with user/password when maven is working?


(Nicolas Milliard) #1

Hello,

I am trying to use Gradle with an enterprise repository manage by nexus. The nexus repository is accessible via HTTPS with user auhtentication and work well with my ~/.m2/settings.xml configuration (see settings.xml at the end).

However I can’t get this repository working with my Gradle configuration. I tried both with using mavenLocal() or with a specific gradle repository section. In both situation I get a ModuleVersionNotFoundException Could not find com.google.android:support-v4:r12.

The same dependecy work well in a maven project.

Please find below my config details and thanks for Gradle: I am using Gradle 1.4 with Sonatype Nexus 2.3.0-04.

I configure gradlew with the following:

DEFAULT_JVM_OPTS=" \
-Djavax.net.ssl.trustStore=trust.jks \
-Djavax.net.ssl.trustStoreType=jks \
-Djavax.net.ssl.trustStorePassword=password"

My gradle config:

buildscript {
    repositories {
        mavenLocal()
//
    mavenCentral()
        //maven {
          //
credentials {
           //
   username 'user'
            //
  password 'pwd'
            //}
            //url "https://dev/nexus/content/groups/public"
        //}
      }
    dependencies {
        compile 'com.google.android:support-v4:r12'
    }
}

~/.m2/settings.xml

<settings>
  <servers>
    <server>
      <id>nexus</id>
      <username>user</username>
      <password>pwd</password>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>https://dev/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

(Peter Niederwieser) #2

Instead of ‘mavenLocal’, you should use a ‘maven’ repository with the correct URL.

Where did you get the trustStore setup from? Are you doing something similar for Maven? Have you tried to leave it out?

If you are using basic authentication, the ‘credentials’ block is the correct approach. I recommend to check the Gradle and Nexus logs to find out if it really is an authentication problem, and what exactly the problem is.

If you do have the dependency in the local Maven repo, and ‘mavenLocal()’ didn’t work either, then it’s probably not an authentication problem. For one thing, inside ‘buildscript.dependencies’ you can only add dependencies to the ‘classpath’ configuration; there is no ‘compile’ configuration. I’d be surprised if that didn’t give an error.

Last but not least, try to run with ‘–refresh-dependencies’ after making a change.


(Nicolas Milliard) #3

Thanks for your answer, I found my issue.

It was because I use subprojects and I configure the remote repository only in buildscript section.

To solve the issue, I added:

allprojects {
    // Add Buildscript repository
    rootProject.buildscript.repositories.each {
        repositories.add(it)
    }
}