Last active
June 27, 2018 15:01
-
-
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.
This file contains 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
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}" | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains 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
$ gradle uploadArchives |
This file contains 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
signing.keyId= | |
signing.password= | |
signing.secretKeyRingFile= | |
mavenRepositoryPassword= | |
mavenRepositoryUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ | |
mavenRepositoryUsername= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this example !
For people who will come later, to generate the required keyring file:
gpg --export-secret-keys -o secring.gpg