Skip to content

Instantly share code, notes, and snippets.

@tbarker9
Last active December 18, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbarker9/5825298 to your computer and use it in GitHub Desktop.
Save tbarker9/5825298 to your computer and use it in GitHub Desktop.
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