Skip to content

Commit

Permalink
Replaces Bintray gradle plugin with maven-publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Sanson committed Apr 30, 2018
1 parent 04a19a0 commit 5c383b9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 109 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {
}
dependencies {
classpath "com.android.tools.build:gradle:$gradle_version"
classpath "digital.wup:android-maven-publish:$android_maven_version"
}
}

Expand Down
6 changes: 4 additions & 2 deletions common.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
ext.version = "1.0.5"
ext.version = "1.0.6"
ext.group = "nz.co.trademe.mapme"
ext.repo = "MapMe"
ext.org = "trademe"
ext.scm = 'https://github.com/TradeMe/MapMe.git'
ext.description = 'MapMe is an Android library that brings the adapter pattern to Maps, simplifying the management of markers and annotations.'

ext.compileSdk = 27
ext.minSdk = 15
ext.buildTools = "27.0.3"
ext.kotlin_version = '1.2.31'
ext.bintray_version = '1.7.3'
ext.dokka_version = '0.9.15'
ext.gradle_version = '3.1.0'
ext.mapbox_version = '5.1.3'
ext.google_play_services_version = '11.8.0'
ext.android_support_version = '27.0.1'
ext.android_maven_version = '3.3.0'

1 change: 0 additions & 1 deletion googlemaps/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ buildscript {
mavenLocal()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
1 change: 0 additions & 1 deletion mapbox/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ buildscript {
mavenLocal()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
1 change: 0 additions & 1 deletion mapme/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ buildscript {
mavenLocal()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
127 changes: 24 additions & 103 deletions publishing.gradle
Original file line number Diff line number Diff line change
@@ -1,116 +1,37 @@
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
if (project.plugins.hasPlugin("com.android.library")) {

project.afterEvaluate {
if (project.plugins.hasPlugin("com.android.library")) {
apply plugin: 'digital.wup.android-maven-publish'

project.android.libraryVariants.all { variant ->
variant.outputs.all {
def newName = "${project.name}-v${project.version}.aar"
outputFileName = newName
}
}
}
}

project.group = project.ext.group
project.version = project.ext.version

bintray {
user = project.hasProperty("BINTRAY_USERNAME") ? project.property('BINTRAY_USERNAME') : null
key = project.hasProperty("BINTRAY_API_KEY") ? project.property('BINTRAY_API_KEY') : null
pkg {
repo = 'MapMe'
name = getArtifactId()
userOrg = 'trademe'
licenses = ['Apache-2.0']
vcsUrl = project.ext.scm
version {
name = project.version
desc = project.ext.description
released = new Date()
vcsTag = project.version
project.afterEvaluate {
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
}
publications = ['Bintray']
}
}

// Create the pom configuration:
def pomConfig = {
licenses {
license {
name "MIT License"
url "http://www.opensource.org/licenses/mit-license.php"
distribution "repo"
publishing {
publications {
aar(MavenPublication) {
from project.components.android
artifact project.sourcesJar {
// not required, includes sourcesJar with correct classifier
classifier "sources"
}
groupId project.group
artifactId project.name
version project.ext.version
}
}
}
scm {
url ext.scm
}
}

//create a jar from source files
task sourceJar(type: Jar) {
if (project.plugins.hasPlugin("com.android.library")) {
from android.sourceSets.main.java.srcDirs
classifier "sources"
}
}

publishing.publications {
Bintray(MavenPublication) {
groupId project.ext.group
artifactId getArtifactId()
version project.ext.version
repositories {
maven {
name 'Bintray'
url "https://api.bintray.com/maven/${project.org}/${project.repo}/${project.name}/;publish=1"

artifact sourceJar
artifact "$buildDir/outputs/aar/${project.name}-v${project.version}.aar"

//generate pom nodes for dependencies
//when a project references another project, it's artifact node is generated
pom.withXml {
def root = asNode()
root.appendNode('description', project.ext.description)
root.appendNode('name', project.ext.name)
root.appendNode('url', project.ext.scm)
root.children().last() + pomConfig

def dependenciesNode = root.appendNode('dependencies')

configurations.compile.allDependencies.each { dependency ->
if (dependency.group != null && dependency.name != null) {

if (dependency instanceof ProjectDependency) {
dependency.getDependencyProject().getArtifacts().each { artifact ->
addDependencyNodeToPom(dependenciesNode, dependency.group, getArtifactId(dependency.dependencyProject), dependency.version)
}
} else {
addDependencyNodeToPom(dependenciesNode, dependency.group, dependency.name, dependency.version)
}
credentials {
username BINTRAY_USERNAME
password BINTRAY_API_KEY
}
}
}
}
}

def getArtifactId() {
return getArtifactId(project)

}

def getArtifactId(someProject) {
if (!someProject.ext.has('artifactId')) {
//default artifactId is the project/module name
return someProject.getName();

}
return someProject.ext.artifactId;
}


def addDependencyNodeToPom(dependenciesNode, group, artifact, version) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode("groupId", group)
dependencyNode.appendNode("artifactId", artifact)
dependencyNode.appendNode("version", version)
}

0 comments on commit 5c383b9

Please sign in to comment.