Question

How can I get gradle 1.10 to use my local maven repository? When I run my gradle script it always looks for the artifact in /Applications/Android Studio.app/sdk/extras/android/m2repository/ instead of ${HOME}/.m2/repository/

In the build.gradle I have tried:

repositories {
    mavenCentral()
    mavenLocal()
 }

and tried this:

repositories {
    mavenCentral()
    maven {
        url '${HOME}/.m2/repository/'
    }
 }

I then have a dependency that is located in my local .m2 repository:

dependencies {
    compile 'com.android.support:support-v4:20.0.+'
    compile 'com.android.support:appcompat-v7:20.0.+'
    compile 'com.google.android.gms:play-services:4.0.30'
    compile 'com.profferapp:proffer_dto_customer_android:1.0'
    compile 'com.test:artifact:1.0' // this is in my .m2 repository
}

None of these configurations point to my local maven repository.

Was it helpful?

Solution

If you want to do ${...} variable substitution, you need to use double quotes (") instead of single quotes ('). Double quotes denote GStrings, which can do that, but strings with single quotes are always interpreted literally.

So:

repositories {
    mavenCentral()
    maven {
        url "${HOME}/.m2/repository/"
    }
 }

Make sure you put this block in your module's build file, not the buildscript block of the top-level build file; the latter only determines where to find the Android plugin, not your module-specific dependencies

Because of the misquoted string, it's probably not seeing your local repository. Also, the other question about the plugin implicitly adding the Maven repo in your SDK is also correct. This will pick up Android support dependencies.

Gradle Single vs Double Quotes has a little more information and a link you can follow.

OTHER TIPS

I want to comment Scott Barta's answer but I have not enough reputation.

  1. $HOME does not works for me (in CLI, not Android Studio), System.getenv('HOME') does
  2. it's not necessary to put the repositories block into EVERY modules' build.gradle file, just put the block inside a "allprojects" block in the top-level build.gradle (I learned it here)

So, the final solution I use is:

// in the top-level build.gradle:
buildscript {
    ...
}

allprojects {
    repositories {
        mavenCentral()
        maven { url System.getenv('HOME') + "/.m2/repository/" }
    }
}

When you do apply plugin: 'android'

the android plugin adds another repository - the one under your SDK. It contains those support and extension libraries. com.test:artifact:1.0 is likely taken form you local Maven repository.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top