Skip to content

Instantly share code, notes, and snippets.

@suwhs
Last active January 4, 2021 22:17
Show Gist options
  • Save suwhs/811bbe43315abaef3b5e to your computer and use it in GitHub Desktop.
Save suwhs/811bbe43315abaef3b5e 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-plugin:1.2'                 // AND THIS LINE
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

create ~/.gradle/bintray.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 = ['GPL-3.0'] // or something else 
id = <package name>
name = <module name> // actually not used

create deploy.gradle file (WARNING: gpl-3 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 'GPL-3.0'
                    url 'https://www.gnu.org/licenses/gpl.txt'
                    distribution 'repo'
                }
            }
            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 = "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

@danilodequeiroz
Copy link

Error:Cause: deploy.settings (No such file or directory)

@mopinion
Copy link

mopinion commented Feb 5, 2018

maybe "YOUR_MODULE_FOLDER/deploy.settings"
Worked for me

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