Reputation: 21
I've been banging my head on this problem for a few days.
My situation is this:
I have a sdk written by me that uses two dependencies hosted on a private maven repository which can only be accessed via login
This sdk was always used within my Android app (but treated as a sub-module) within the project.
Inside the project’s Gradle there are the 2 maven repositories from which to look for the 2 private dependencies mentioned above.
maven {
name “repo-1”
url "s3://repo-1/maven"
credentials(AwsCredentials) {
accessKey awsUsername
secretKey awsPassword
}
}
maven {
name “repo-2”
url "http://repo-2/repository/maven-releases"
credentials {
username ‘repo-2-name’
password ‘repo-2-password’
}
}
Now I want to completely divide the two things and host the SDK on my private maven repository, in order to hide all the code and the dependencies concerning the SDK from the app.
First I want to do everything locally, so I could be faster to do different tests. I therefore "uploaded" my SDK in my local maven.
In the POM that I generated, I have all the necessary dependencies to the SDK (including the 2 dependencies of the private repositories)like this :
<packaging>aar</packaging>
<dependencies>
<dependency>
<artifactId>repo-1</artifactId>
<groupId>com.repo-1.android</groupId>
<version>0.0.1</version>
</dependency>
<dependency>
<artifactId>repo-2</artifactId>
<groupId>com.repo-2.android</groupId>
<version>1.0.0</version>
</dependency>
and in addition i have also added the 2 repositories from which the 2 private dependencies must be downloaded :
<repositories>
<repository>
<id>repo-1</id>
<name>repository-1</name>
<url>http://repo-1/repository/maven-releases</url>
</repository>
<repository>
<id>repo-2</id>
<name>repository-2</name>
<url>s3://repo-1/maven</url>
</repository>
</repositories>
I then set the settings.xml file , in the root of my local maven (../.m2) , with the credentials to access the 2 repositories.
<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>repo-1</id>
<username>awsPassword</username>
<password>awsPassword</password>
</server>
<server>
<id>repo-2</id>
<username>repo-2-name</username>
<password>repo-2-password</password>
</server>
</servers>
</settings>
I then added my sdk as a dependency within the app, but does not want to download the 2 dependencies from the private repositories.
BUT
If I add the two maven repository in the gradle of the app project (like the first example), however, it works, so I'm pretty sure it's a problem of pom and setting.xml configuration.
Thank you very much to everyone for any answers
Upvotes: 2
Views: 5023
Reputation: 14510
What you are facing is a difference between the way Maven and Gradle handle repositories.
In short Gradle is more strict and will not transparently download dependencies from repositories that are not declared in a build script.
For more details on why this is the case, have a look at the discussion in the Gradle issue tracker.
So the solution, as you found out, is to declare these repositories in the consuming build script. If you believe that's too verbose, consider writing a minimal plugin for your SDK that would add the dependencies and the repositories.
It would then become:
plugins {
id 'my-sdk-plugin'
}
Upvotes: 1