Skip to content

Instantly share code, notes, and snippets.

@rockymadden
Last active June 27, 2018 15:01
Show Gist options
  • Save rockymadden/4643757 to your computer and use it in GitHub Desktop.
Save rockymadden/4643757 to your computer and use it in GitHub Desktop.
Deploy a Gradle Scala project to Maven Central, or any Maven repository for that matter, based upon the presence of variables in your gradle.properties file. Plays nicely with continuous integration tools like Travis-CI.
apply plugin: 'maven'
apply plugin: 'scala'
apply plugin: 'signing'
def isMavenDeployable = hasProperty('mavenRepositoryUrl') &&
hasProperty('mavenRepositoryUsername') &&
hasProperty('mavenRepositoryPassword')
if (isMavenDeployable) {
signing {
sign configurations.archives
}
task scaladocJar(type: Jar, dependsOn: scaladoc) {
classifier = 'javadoc'
from "${project.buildDir}/docs/scaladoc"
}
task sourceJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives jar
archives scaladocJar
archives sourceJar
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: mavenRepositoryUrl) {
authentication(userName: mavenRepositoryUsername, password: mavenRepositoryPassword)
}
pom.project {
description "${parent.project.description}"
groupId "${parent.project.group}"
name "${project.name}"
packaging 'jar'
url "${parent.project.url}"
version "${parent.project.version}"
developers {
developer {
id 'rockymadden'
name 'Rocky Madden'
}
}
licenses {
license {
name 'Apache License v2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
url "${parent.project.scm}"
connection "${parent.project.scm}"
}
}
}
}
}
}
$ gradle uploadArchives
signing.keyId=
signing.password=
signing.secretKeyRingFile=
mavenRepositoryPassword=
mavenRepositoryUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2/
mavenRepositoryUsername=
@Fraer
Copy link

Fraer commented Jun 27, 2018

Thank you for this example !

For people who will come later, to generate the required keyring file:
gpg --export-secret-keys -o secring.gpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment