Skip to content

Instantly share code, notes, and snippets.

@tbarker9
Last active Dec 18, 2015
Embed
What would you like to do?
bintray generic upload gradle task. Stole directly from https://github.com/pledbrook/lazybones
class BintrayGenericUpload extends DefaultTask {
@InputFile
File artifactFile
@Input
String artifactUrl
@TaskAction
def publish() {
def username = project.getProperty("repo.username")
def password = project.getProperty("repo.apiKey")
def url = new URL(project.getProperty("repo.url") + "/" + artifactUrl)
logger.lifecycle "Streaming artifact to Bintray at URL ${url}"
url.openConnection().with {
// Add basic authentication header.
setRequestProperty "Authorization", "Basic " + "$username:$password".getBytes().encodeBase64().toString()
doOutput = true
fixedLengthStreamingMode = artifactFile.size()
requestMethod = "PUT"
def inputStream = artifactFile.newInputStream()
try {
outputStream << inputStream
}
finally {
inputStream.close()
outputStream.close()
}
assert responseCode >= 200 && responseCode < 300
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment