Simple way to publish your Android library to JCenter

Yegor Zatsepin
Aug 24, 2017 · 4 min read

1. Setup your repository on Bintray

2. Setup your Android library project

bintray.user=USERNAME
bintray.apikey=API_KEY
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'

}
}

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
ext {
bintrayRepo = 'maven'
bintrayName = 'diagonalscrollview'

publishedGroupId = 'ua.org.tenletters.widget'
libraryName = 'DiagonalScrollView'
artifact = 'diagonalscrollview'

libraryDescription = 'This view is a container that supports diagonal scroll and fling gesture. It is based on AOSP HorizontalScrollView.'

siteUrl = 'https://github.com/LissF/DiagonalScrollView'
gitUrl = 'https://github.com/LissF/DiagonalScrollView.git'

libraryVersion = '0.3.3'

developerId = 'lissf'
developerName = 'Yegor Zatsepin'
developerEmail = 'Liss_F@ukr.net'

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
group = publishedGroupId
version = libraryVersion

install {
repositories.mavenInstaller {
pom.project {
packaging 'aar'
groupId publishedGroupId
artifactId artifact

name libraryName
description libraryDescription
url siteUrl

licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}

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))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives javadocJar
archives sourcesJar
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

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

configurations = ['archives']
pkg {
repo = bintrayRepo
name = bintrayName
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
dryRun = false
publish = true
override = false
publicDownloadNumbers = true
version {
desc = libraryDescription
}
}
}
apply from: 'LINK_TO_SCRIPT'

3. Package and upload your library

clean” is optional

Yegor Zatsepin

Written by

Senior Android Developer, Raspberry Pi enthusiast, Dungeon Master.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade