Skip to content

Instantly share code, notes, and snippets.

@Sorbh
Last active February 28, 2018 13:47
Show Gist options
  • Save Sorbh/ed41464f9ada9bfb49e6a13447dd28ed to your computer and use it in GitHub Desktop.
Save Sorbh/ed41464f9ada9bfb49e6a13447dd28ed to your computer and use it in GitHub Desktop.
Bintray-upload build.gradle (for jcenter)

Add maven and bintray plugin to your root gradle file build script dependencies(root project gradle.build)

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

Your build scipt dependencies should look like this

 dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // Required plugins added to classpath to facilitate pushing to Jcenter/Bintray
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

Create key property file in .gradle/bintray.properties

bintray.user=<Bintray User Name>
bintray.apikey=<Bintray API Key>

Create deploy.gradle file in your module, parallel to your module gradle.build file and paste the code below

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

def artifact = new Properties()
artifact.load(new FileInputStream("deploy.properties"))

version=artifact.version
group=artifact.groupId

install {
    repositories.mavenInstaller {
        pom.project {
            packaging 'aar'
            groupId artifact.groupId
            artifactId artifact.id
            version artifact.version
            name artifact.id // pom.project.name must be same as bintray.pkg.name
            url artifact.siteUrl
            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                }
            }
            developers {
                developer {
                    id '<developer id>'
                    name '<your name>'
                    email '<contact mail id>'
                }
            }
            scm {
                connection artifact.gitUrl
                developerConnection artifact.gitUrl
                url artifact.siteUrl
            }
        }
    }
}

Properties properties = new Properties()
File propFile = "${System.properties['user.home']}${File.separator}.gradle${File.separator}bintray.properties" as File
properties.load(propFile.newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = "<bintray Repo Name>"
        name = artifact.id
        websiteUrl = artifact.siteUrl
        vcsUrl = artifact.gitUrl
        licenses = artifact.licenses
        publish = true
        version {
            name = artifact.version
        }
    }
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
    // options.encoding = 'UTF-8'
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

Create deploy.setting file in the root project, parallel to root project gradle.build file and paste the code below

siteUrl = <link to GIT repo>
gitUrl = <git link GIT repo>
version = <version of library>
licenses = ['Apache-2.0'] // Applied licence, change the same in deploy.gradle file
groupId = <group id> //unique for maven repo , mostly the package name of the module
id = <package name> //Be careful about this
name = <module name>

Add this in the end of your modules(library) gradle.build file

apply from: 'deploy.gradle'

Cd terminal to the root of the Android project and Run these commands.

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