Skip to content

Instantly share code, notes, and snippets.

@Kishanjvaghela
Forked from suwhs/gradle.md
Last active September 29, 2018 15:18
Show Gist options
  • Save Kishanjvaghela/b8b5724ee5ff712cee3a8f3a3c2c5937 to your computer and use it in GitHub Desktop.
Save Kishanjvaghela/b8b5724ee5ff712cee3a8f3a3c2c5937 to your computer and use it in GitHub Desktop.
5 steps for bintray-upload build.gradle (for jcenter)

add bintray and maven plugin to buildscript dependencies (project's build.gradle)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.2'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'            // ADD THIS LINE
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'                 // AND THIS LINE
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

add lines in /local.properties

bintray.apikey=<apikey>
bintray.user=<username>

create deploy.settings in module to publish

siteUrl = <url-of-site-with-information-about-library>
gitUrl = <git url> 
version = x.y.z
groupId = <group id>
licenses = ['Apache-2.0'] // or something else 
id = <package name>
name = <module name> // actually not used

create deploy.gradle file (WARNING: Apache-2.0 license hardcoded for .pom file)

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

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

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
            inceptionYear '2015' // HARDCODED
            licenses {
                 license { // HARDCODED
                    name 'The Apache Software License, Version 2.0'
                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    distribution 'repo'
                }
            }
            scm {
                    connection artifact.gitUrl
                    developerConnection artifact.gitUrl
                    url artifact.siteUrl
            }
        }
    }
}

def properties = new Properties()
properties.load(new FileInputStream("local.properties"))

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

    configurations = ['archives']
    pkg {
        repo = "maven"
        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
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
}

add at the end of module's build.gradle

apply from: 'deploy.gradle'

run ./gradlew install - to install package into local maven repository ./gradlew bintrayUpload - to upload package to bintray

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