This example shows you how to deploy your own Android library to your own server with gradle.
- Webspace or Server with access over ssh (i.e. uberspace.de)
- That's all
First step is to creating an Android lib. Well.
To deploy the lib you need the maven plugin in your module build.gradle
.
apply plugin: 'com.android.library'
apply plugin: 'maven'
android {
[...]
}
In the same build.gradle
you need to setup a new configuration under the android section.
configurations {
deployerJars
}
You need also a new dependency for that new created configuration. For uploading via ssh all you need is he org.apache.maven.wagon:wagon-ssh:2.2
.
Your dependencies section look like that now
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
[...]
// Your lib dependencies
[...]
deployerJars "org.apache.maven.wagon:wagon-ssh:2.2"
}
To upload the library to your own specific servers the gradle file need the uploadArchives section.
uploadArchives {
repositories.mavenDeployer {
configuration = configurations.deployerJars
repository(url: "scp://your.company.domain.or.something/folder/on/your/server/where/to/deploy") {
authentication(userName: "sshUserName", password: "sshPassword")
}
pom.groupId = 'your.groupId'
pom.artifactId = 'artifactId'
pom.version = 'versionNumber'
}
}
That's all. Sync your gradle and be happy. The final step to upload the lib is to open the terminal and say
./gradlew uploadArchives
Urgh, yeah. I think so :)
When you first deploy your library via the gradlew
command, you must trust the RSA fingerprint.
So it is a benefit to run this command with the --debug
option.
Gradle ask your like this
Are you sure you want to continue connecting (yes/no)?
and you need to type yes.
Another thing what is important, maybe, is how to use the uploaded lib in other projects.
We take the example from above.
First think is to setup the "new maven repository" in your root build.gradle
like this
allprojects {
repositories {
jcenter()
maven { url "http://your.company.domain.or.something/deploy" }
}
}
Now the gradle system will look up on these repository when they refresh the dependencies.
To add the lib as dependency you need to setup the module build.grade
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'your.groupId:artifactId:versionNumber'
}
Sync and stay happy!