Skip to content

Instantly share code, notes, and snippets.

@koush
Last active December 17, 2015 22:09
Show Gist options
  • Save koush/5679894 to your computer and use it in GitHub Desktop.
Save koush/5679894 to your computer and use it in GitHub Desktop.
gradle.include
// Setup
// 0) Setup your sonatype credentials by editing/creating ~/.gradle/gradle.properties and enter:
// signing.keyId=<HEXADECIMCAL KEY ID RETRIVABLE VIA gpg --list-keys>
// signing.password=<KEY PASSWORD>
// signing.secretKeyRingFile=<PATH TO KEY RING, USUALLY ~/.gnupg/secring.gpg>
// sonatypeUsername=<SONATYPE USERNAME OR WHATEVER YOU USE>
// sonatypePassword=<CORRESPONDING PASSWORD>
// 1) Setup your build.gradle for your android project and add this one line of code which imports this gist:
// apply from: 'https://gist.github.com/koush/5679894/raw/07b5a99fb8909b58350631c24a81f3ef732be71d/maven.gradle'
// 2) gradle clean && gradle build && gradle uploadArchives
// 3) That's it!
apply plugin: 'maven'
apply plugin: 'signing'
signing {
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
user = null
repo = null
'git remote -v'.execute(null, new File(file('.').absolutePath)).getText().find('[email protected]:(.*?)/(.*?).git') {
match ->
user = match[1]
repo = match[2]
}
repoInfo = new groovy.json.JsonSlurper().parseText(new URL('https://api.github.com/repos/' + user + '/' + repo).getText())
android_manifest = new XmlParser(false, false).parseText(new File('AndroidManifest.xml').getText())
version = android_manifest.'@android:versionName'
package_name = android_manifest.'@package'
beforeDeployment { MavenDeployment deployment -> signPom(deployment) }
pom.groupId = package_name
pom.artifactId = repo.toLowerCase()
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
pom.project {
name repo
packaging 'jar'
description repoInfo.description
url repoInfo.html_url
scm {
url repoInfo.git_url
connection repoInfo.git_url
developerConnection repoInfo.ssh_url
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id user
name user
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment