Skip to content

Instantly share code, notes, and snippets.

@bmoliveira
Last active February 16, 2018 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmoliveira/3d9c28aaaa737aba9ad5fd894603395b to your computer and use it in GitHub Desktop.
Save bmoliveira/3d9c28aaaa737aba9ad5fd894603395b to your computer and use it in GitHub Desktop.
BintrayUpload via providing properties
// This script will configure the deploy to bintray with aar
// Of an android-library using kotlin project
// Simply by providing the .property files
// all boilerplate code is here.
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'maven-publish'
//
// You must have in your root project a local.properties file
// And in your project root a deploy.properties
// With the following properties set
//
// deploy.mavenRepo=<maven-package> // Bintray package
// deploy.group=<group-id> // Bintray group
// deploy.artifactID=<artifact-id> // Artifact id
// deploy.version=<version> // Current lib version
// deploy.shouldPublish=true // Optional: [Default: true] Whether version should be auto published after an upload
// deploy.shouldOverride=true // Optional: [Default: false] Whether to override version artifacts already published
//bintray.user=<user> // Bintray username
//bintray.apikey=<apikey> // Bintray api key
// Get local.properties file
Properties localProperties = new Properties()
localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
// Get deploy properties config file
Properties deployProperties = new Properties()
deployProperties.load(project.file('deploy.properties').newDataInputStream())
def getProperty = { String propertyName ->
deployProperties.get(propertyName) ?: localProperties.get(propertyName)
}
version = getProperty("deploy.version")
group = getProperty("deploy.group")
//take a look at https://github.com/bintray/gradle-bintray-plugin#buildgradle
bintray {
user = getProperty("bintray.user")
key = getProperty("bintray.apikey")
configurations = ['archives']
publish = getProperty("deploy.shouldPublish") ?: true
override = getProperty("deploy.shouldOverride") ?: false
pkg {
repo = getProperty("deploy.mavenRepo")
name = getProperty("deploy.artifactID")
version {
name = getProperty("deploy.version")
}
}
}
install {
repositories.mavenInstaller {
pom.project {
packaging 'aar'
groupId getProperty("deploy.group")
artifactId getProperty("deploy.artifactID")
version getProperty("deploy.version")
name getProperty("deploy.artifactID")
}
}
}
if (project.hasProperty("kotlin")) { //Kotlin libraries
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
task javadoc(type: Javadoc, dependsOn: dokka) {
}
} else if (project.hasProperty("android")) {
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
} else { // Java libraries
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
@bmoliveira
Copy link
Author

bmoliveira commented Feb 16, 2018

Use with raw link, like this:

 apply from: 'https://gist.githubusercontent.com/bmoliveira/3d9c28aaaa737aba9ad5fd894603395b/raw/48c34ade38f142ec11325579d9c9cffc63586194/bintray-deploy.gradle' 

And add a properties file to project with config vars:

bintray.user=<USERNAME>
bintray.apikey=<API_KEY>
#Optional
bintray.gpg.password=<YOUR_GPG_PASSWORD>

deploy.mavenRepo=<REPO>
deploy.group=<com.yourcompany>

#Default to true
deploy.shouldPublish=true
deploy.shouldOverride=true

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