14

I would like to know if there is a way to force gradle to use a repository for one dependency. For instance with:

buildscript {
repositories {
    jcenter()
    mavenCentral()
    maven { url 'https://www.testfairy.com/maven' }
    maven { url 'https://maven.fabric.io/repo' }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

dependencies {
    classpath 'com.android.tools.build:gradle:1.0.1'
    classpath "io.fabric.tools:gradle:1.+"
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
compile project(':shimmer')
compile('com.twitter.sdk.android:twitter:1.1.1@aar') {
    transitive = true;
}
compile('com.twitter.sdk.android:tweet-composer:0.7.2@aar') {
    transitive = true;
}
compile 'com.android.support:appcompat-v7:21.0.3'
// Dagger 2 dependencies
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'

}

I want com.google.dagger to be checked out from https://oss.sonatype.org/content/repositories/snapshots because for now it tries to check it out from https://maven.fabric.io/repo which result in the following error:

Error:Could not GET 'https://maven.fabric.io/repo/com/google/dagger/
dagger-compiler/2.0-SNAPSHOT/maven-metadata.xml'. Received status code 401      from server: Unauthorized
<a href="toggle.offline.mode">Enable Gradle 'offline mode' and sync project</a>

Thank you.

E-Kami
  • 2,529
  • 5
  • 30
  • 50

2 Answers2

10

Same thing happened to me last night, I could solve by adding the following lines in gradle file.

compile 'com.google.dagger:dagger:2.1-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.1-SNAPSHOT'

Version 2.0 is not already available in the repository.

Yuva Raj
  • 3,881
  • 1
  • 19
  • 30
1

No, not yet. The ordering is important, so you could try putting the fabric.io repo last.

When I try this locally from the command-line, I see dagger come from sonatype without changing anything. Does it work from the command-line for you too?

bigguy
  • 973
  • 9
  • 13
  • 1
    I figured out why it didn't work. I had `repositories {maven { url "https://oss.sonatype.org/content/repositories/snapshots" }}` under my `apply plugin` in my gradle file. I added `maven { url "https://oss.sonatype.org/content/repositories/snapshots" }` under it and it worked. But still, I don't understand why we can't specify which repo to use for specific dependencies. – E-Kami Feb 24 '15 at 00:12