Last active
August 29, 2015 14:02
-
-
Save akhikhl/b1adb427491ef410448d to your computer and use it in GitHub Desktop.
Working gradle script for bintray and maven central upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is working gradle script for uploading artifacts of the given project | |
// to bintray/jcenter and to maven central (via bintray "sync to maven central" function). | |
// This script can be included from other scripts via `apply from: 'filename'` syntax. | |
apply plugin: 'signing' | |
apply plugin: 'maven-publish' | |
apply plugin: 'bintray' | |
import org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact | |
version = '1.0.0' | |
description = 'Project description goes here' | |
ext { | |
project_id = 'MyProjectId' | |
developer_id = 'developer1' | |
developer_name = 'Full Developer Name' | |
project_website = "https://github.com/${developer_id}/${project_id}" | |
project_scm = "scm:[email protected]:${developer_id}/${project_id}.git" | |
license = 'Apache 2.0 License' | |
license_url = "https://raw.github.com/${developer_id}/${project_id}/master/LICENSE" | |
} | |
install.repositories.mavenInstaller.pom*.whenConfigured { pom -> | |
pom.project { | |
name project.name | |
packaging 'jar' | |
description project.description | |
url project.project_website | |
scm { | |
url project.project_scm | |
connection project.project_scm | |
developerConnection project.project_scm | |
} | |
licenses { | |
license { | |
name project.license | |
url project.license_url | |
distribution 'repo' | |
} | |
} | |
developers { | |
developer { | |
id project.developer_id | |
name project.developer_name | |
} | |
} | |
} | |
} | |
def thisProject = project | |
bintray { | |
// hasProperty to make Gradle happy when bintrayXXX properties are not defined | |
// and we don't call any bintray tasks. | |
user = thisProject.hasProperty('bintrayUser') ? thisProject.bintrayUser : '' | |
key = thisProject.hasProperty('bintrayKey') ? thisProject.bintrayKey : '' | |
configurations = ['archives'] | |
pkg { | |
repo = 'maven' | |
name = thisProject.rootProject.project_id | |
desc = thisProject.rootProject.description | |
licenses = [ thisProject.rootProject.license ] | |
labels = [ 'label1', 'label2' ] | |
} | |
dryRun = false | |
} | |
bintrayUpload { | |
doFirst { | |
// here we sign every archives artifact, then add all signature files to artifacts | |
// (not needed for jcenter upload, needed for maven central upload) | |
def signatureArtifacts = [] | |
collectArtifacts(project.configurations.archives).each { a -> | |
def s = signing.sign(a.file) | |
s.signatureFiles.each { f -> | |
def fname = f.name | |
def ext = fname.substring(fname.lastIndexOf('.') + 1) | |
signatureArtifacts.add(new DefaultPublishArtifact(a.name, a.extension + '.' + ext, ext, a.classifier, new Date(), f, [] as Object[])) | |
} | |
} | |
project.configurations.archives.artifacts.addAll(signatureArtifacts) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment