Created
May 31, 2013 10:45
-
-
Save tbarker9/5684208 to your computer and use it in GitHub Desktop.
upload to bintray gradle task. Probably should consider making this a gradle plugin
This file contains hidden or 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
task uploadToBintray(dependsOn: ["prepareForBintrayUpload", "publishBintrayPackages"]) | |
task prepareForBintrayUpload << { | |
if (version.contains("SNAPSHOT")) { | |
println "bintray does not support SNAPSHOTs, skipping upload to bintray" | |
uploadArchives.enabled = false | |
publishBintrayPackages.enabled = false | |
return | |
} | |
if (!project.hasProperty("bintrayUsername")) { | |
println "bintray credentials not setup, skipping upload to bintray" | |
uploadArchives.enabled = false | |
publishBintrayPackages.enabled = false | |
return | |
} | |
def json = new URL("https://api.bintray.com/packages/upennlib/metridoc/metridoc-job-core").text | |
def slurper = new JsonSlurper() | |
def versions = slurper.parseText(json).versions | |
def versionAlreadyDeployed = versions.contains(version) | |
if (versionAlreadyDeployed) { | |
println "version $version has already been deployed to bintray, skipping upload to bintray" | |
uploadArchives.enabled = false | |
publishBintrayPackages.enabled = false | |
} | |
} | |
task publishBintrayPackages(dependsOn: "uploadArchives") << { | |
def client = new RESTClient("https://api.bintray.com/") | |
client.authorization = new HTTPBasicAuthorization(bintrayUsername, bintrayPassword) | |
def response = client.post( | |
path: "/content/upennlib/metridoc/metridoc-job-core/$version/publish", | |
accept: ContentType.JSON | |
) { | |
type ContentType.JSON | |
charset "utf-8" | |
text "" | |
} | |
println response.getContentAsString() | |
assert 200 == response.statusCode | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this also requires the following addition to the build classpath:
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.github.groovy-wslite:groovy-wslite:0.7.2' } }