Maven – How to configure maven local and remote repository in gradle build file

gradlemaven

i want to use the maven local repository additionally to a maven remote one. I found the JIRA-Issue http://issues.gradle.org/browse/GRADLE-1173 for that, but adapting my gradle build file in that way some snapshot dependencies which are only available in the local maven repository are still not found. I get an error that the Snapshot-Dependency is not found.

Is it possible to have one local and one remote maven repository?

Here is the relevant part of my gradle build file:

apply plugin: 'maven'

repositories {

    mavenLocal()

    maven {
        credentials {
            username "myusername"
            password "mypassword"
        }
        url "http://myremoterepository"
    }

}

Best Answer

I also needed to do a similar setup with my project and I can verify your build.gradle setup works provided your Maven is setup correctly.

Gradle's mavenLocal() relies on the localRepository definition from the maven settings.xml file:

  <localRepository>USER_HOME\.m2\repository</localRepository>

The settings.xml should be in either your M2_HOME/conf or your USER_HOME/.m2 directory. You should check:

  1. maven is installed correctly
  2. M2_HOME environment variable exists
  3. settings.xml has the correct localRepository defined..