Skip to content

Instantly share code, notes, and snippets.

@cwc
Created August 20, 2014 22:15
Show Gist options
  • Save cwc/3263c01ac4671ef4f0d0 to your computer and use it in GitHub Desktop.
Save cwc/3263c01ac4671ef4f0d0 to your computer and use it in GitHub Desktop.
Gradle skeleton for publishing to Maven Central
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'
group = 'io.example'
archivesBaseName = 'example-artifact'
version = '1.0-SNAPSHOT'
ext.pomPackaging = 'jar'
ext.pomName = 'Example artifact'
ext.pomDescription = 'An example artifact'
ext.pomProjectUrl = 'https://example.github.io/example-artifact'
ext.pomScmWebUrl = 'https://github.com/example/example-artifact'
ext.pomLicenseName = 'MIT License'
ext.pomLicenseUrl = 'https://www.tldrlegal.com/l/mit'
ext.pomDeveloperId = 'exDev'
ext.pomDeveloperName = 'Example Developer'
ext.pomDeveloperEmail = 'exDev@example.com'
// Generates a sources jar
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
}
// Generates a Javadoc jar
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}
// Maven Central publishing configuration (`gradlew uploadArchives`)
artifacts {
archives javadocJar, sourcesJar
}
signing {
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: mavenCentralUser, password: mavenCentralPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: mavenCentralUser, password: mavenCentralPassword)
}
pom.project {
name project.ext.pomName
description project.ext.pomDescription
packaging project.ext.pomPackaging
url project.ext.pomProjectUrl
scm {
url project.ext.pomScmWebUrl
}
licenses {
license {
name project.ext.pomLicenseName
url project.ext.pomLicenseUrl
}
}
developers {
developer {
id project.ext.pomDeveloperId
name project.ext.pomDeveloperName
email project.ext.pomDeveloperEmail
}
}
}
}
}
}
mavenCentralUser=example
mavenCentralPassword=examplePassword
signing.keyId=EXAM2383PLE
signing.password=examplePassword
signing.secretKeyRingFile=d:/cygwin/home/example/.gnupg/secring.gpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment