6
votes

Here is how my application module 'app' build gradle looks like:

apply plugin: 'com.android.application'

repositories {
    maven { url 'http://localhost:8080/repository/internal/' }
}

...

dependencies {
    compile 'org.apache.httpcomponents:httpmime:4.2.3'
    compile 'com.testpackage.networking:networking:1.0.3'
}

and it works just fine. I'm trying to use same dependency in my library module named 'librarymodule'. Here is how its build.gradle looks like:

apply plugin: 'com.android.library'

repositories {
    maven {
        url 'http://localhost:8080/repository/internal/'
    }
}

...

dependencies {
    compile 'org.apache.httpcomponents:httpmime:4.2.3'
    compile 'com.testpackage.networking:networking:1.0.3'
}

The only difference is gradle plugin 'com.android.library' used here vs 'com.android.application' used in 'app' module.

Error:A problem occurred configuring project ':app'. Could not resolve all dependencies for configuration ':app:_debugCompile'. Could not find com.testpackage.networking:networking:1.0.3. Searched in the following locations: https://jcenter.bintray.com/com/testpackage/networking/networking/1.0.3/networking-1.0.3.pom https://jcenter.bintray.com/com/testpackage/networking/networking/1.0.3/networking-1.0.3.jar file:/Users/myusername/Library/Android/sdk/extras/android/m2repository/com/testpackage/networking/networking/1.0.3/networking-1.0.3.pom file:/Users/myusername/Library/Android/sdk/extras/android/m2repository/com/testpackage/networking/networking/1.0.3/networking-1.0.3.jar file:/Users/myusername/Library/Android/sdk/extras/google/m2repository/com/testpackage/networking/networking/1.0.3/networking-1.0.3.pom file:/Users/myusername/Library/Android/sdk/extras/google/m2repository/com/testpackage/networking/networking/1.0.3/networking-1.0.3.jar Required by: LibrariesApplication:app:unspecified > LibrariesApplication:librarymodule:unspecified

So, for some reason there is no http://localhost:8080/repository/internal/com/testpackage/networking/networking/1.0.3/networking-1.0.3.pom under Searched in the following locations list.

It's not only my repository problems. I can for example use

maven { url 'https://mint.splunk.com/gradle/' }

repository with dependency

compile 'com.splunk.mint:mint:4.1'

and still getting similar error

Does anyone knows how to fix that?

2

2 Answers

2
votes

This is a bit strange but adding custom repository to 'allprojects' of root build.gradle actually worked!

allprojects {
    repositories {
        jcenter()

        maven {
            url 'http://localhost:8080/repository/internal/'
        }
    }
}
-3
votes

If you don't want to put the maven credentials in the project file (and you shouldn't), create a "gradle.properties" file in your home directory and put the maven credentials in that file, like:

mavenUser=myUser
mavenPassword=myPassword

Then, in your build.gradle file, use as follows:

maven {
    credentials {
        username mavenUser
        password mavenPassword
    }
    url http://my.maven.url
}