Skip to content

Instantly share code, notes, and snippets.

@StefMa
Created August 15, 2015 09:45
Show Gist options
  • Save StefMa/7a4a910e2f570566a0b1 to your computer and use it in GitHub Desktop.
Save StefMa/7a4a910e2f570566a0b1 to your computer and use it in GitHub Desktop.
Deploy your android library to your ssh server with gradle

Deploy your Android library to your server with gradle


What is it?

This example shows you how to deploy your own Android library to your own server with gradle.


What do I need?

  • Webspace or Server with access over ssh (i.e. uberspace.de)
  • That's all

How to use?

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

More to know?

Urgh, yeah. I think so :)

First deploy

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.

Use in other projects

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!


References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment