Skip to content

Instantly share code, notes, and snippets.

@miguelhincapie
Created January 22, 2018 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelhincapie/7ca32d25561fc74b3d4c497758d597ed to your computer and use it in GitHub Desktop.
Save miguelhincapie/7ca32d25561fc74b3d4c497758d597ed to your computer and use it in GitHub Desktop.
gradle configuration file used to publish an android library to jcenter (gradle:3.0.1)
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
// load properties
Properties properties = new Properties()
File localPropertiesFile = project.file("local.properties")
if(localPropertiesFile.exists()){
properties.load(localPropertiesFile.newDataInputStream())
}
else {
throw new GradleException("local.properties file doesn't exist")
}
File projectPropertiesFile = project.file("project.properties")
if(projectPropertiesFile.exists()){
properties.load(projectPropertiesFile.newDataInputStream())
}
else {
throw new GradleException("project.properties file doesn't exist")
}
//read properties
def projectName = properties.getProperty("project.name")
def projectGroupId = properties.getProperty("project.groupId")
def projectArtifactId = properties.getProperty("project.artifactId")
def projectVersionName = android.defaultConfig.versionName
def projectPackaging = properties.getProperty("project.packaging")
def projectSiteUrl = properties.getProperty("project.siteUrl")
def projectGitUrl = properties.getProperty("project.gitUrl")
def projectIssueTrackerUrl = properties.getProperty("project.issueTrackerUrl")
def projectDescription = properties.getProperty("project.description")
def developerId = properties.getProperty("developer.id")
def developerName = properties.getProperty("developer.name")
def developerEmail = properties.getProperty("developer.email")
def bintrayUser = properties.getProperty("bintray.user")
def bintrayApikey = properties.getProperty("bintray.apikey")
def javadocName = properties.getProperty("javadoc.name")
group = projectGroupId
version = projectVersionName
bintray {
user = bintrayUser
key = bintrayApikey
configurations = ['archives']
pkg {
repo = 'maven'
name = projectName
desc = projectDescription
websiteUrl = projectSiteUrl
vcsUrl = projectGitUrl
issueTrackerUrl = projectIssueTrackerUrl
licenses = ['Apache-2.0']
labels = ['android', 'library', 'bottomSheet', 'CoordinatorLayout.Behavior', 'googleMaps-like']
publish = true
publicDownloadNumbers = true
version {
name = projectVersionName
desc = 'Beta version'
released = new Date()
vcsTag = projectVersionName
}
}
}
install {
repositories.mavenInstaller {
pom.project {
name projectName
groupId projectGroupId
artifactId projectArtifactId
version projectVersionName
packaging projectPackaging
url projectSiteUrl
description projectDescription
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection projectGitUrl
developerConnection projectGitUrl
url projectSiteUrl
}
}
}
}
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))
}
// Add compile dependencies to javadoc
afterEvaluate {
javadoc.classpath += files(android.libraryVariants.collect { variant ->
variant.javaCompiler.classpath.files
})
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
// javadoc configuration
javadoc {
options{
encoding 'UTF-8'
charSet 'UTF-8'
author true
version projectVersionName
links 'http://docs.oracle.com/javase/7/docs/api'
title javadocName
}
}
////added to avoid errors related to unknown tags in javadoc
//tasks.withType(Javadoc) {
// options.addStringOption('Xdoclint:none', '-quiet')
// options.addStringOption('encoding', 'UTF-8')
// options.addStringOption('charSet', 'UTF-8')
//}
//but better I defined the tags
javadoc {
options.tags = [ "attr", "hide" ]
}
@miguelhincapie
Copy link
Author

How to use:

  1. Create a file with .gradle extension e.g. bintray.gradle
  2. Move it to your module or project you wanna upload
  3. In the same point create 2 files: local.properties and project.properties
  4. In local.properties add the user and key from your bintray account.
  5. In project.properties add the others vars
  6. Add apply from: 'bintray.gradle' at the end of your build.gradle (module or project)
  7. Execute in Android Studio terminal: gradlew clean build install --info. Then execute gradlew bintrayupload --info


The project.properties files looks like:

#project
project.name=CustomBottomSheetBehavior
project.groupId=com.mahc.custombottomsheetbehavior
project.artifactId=googlemaps-like
project.packaging=aar
project.siteUrl=https://github.com/miguelhincapie/CustomBottomSheetBehavior
project.gitUrl=https://github.com/miguelhincapie/CustomBottomSheetBehavior.git
project.issueTrackerUrl=https://github.com/miguelhincapie/CustomBottomSheetBehavior/issues
project.description=Library focused on get Google Maps 3 states behavior including background image parallax and toolbars animations.

#javadoc
javadoc.name=googlemaps-like API

And the local.properties
#bintray
bintray.user=XXXXXXXXX
bintray.apikey=XXXXXXXXXXXXXXXXXXXXXXXXXxxxx

#developer
developer.id=xxxxxxxxxxxxxxx
developer.name=xxxxxxxxxxxx
developer.email=xxxxxxxxxxxxx@gmail.com

It works with gradle 3.0.1 +

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