Skip to content

Commit

Permalink
Publish to Maven Central
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpanzer committed May 13, 2021
1 parent 5b3b57d commit cf62c61
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 186 deletions.
5 changes: 5 additions & 0 deletions asciidoctorj-pdf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ jrubyPrepare {
}
}
}

ext.publicationName = "mavenAsciidoctorJPdf"

apply from: rootProject.file('gradle/publish.gradle')
apply from: rootProject.file('gradle/signing.gradle')
49 changes: 33 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,36 @@
we don't need to apply the jruby and bintray plugin on the rootProject.
*/
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
}

// modern plugins config
plugins {
id "signing"
id "io.codearte.nexus-staging" version "0.22.0"
id "de.marcphilipp.nexus-publish" version "0.4.0"
id 'com.github.jruby-gradle.base' version '2.0.0'
}

apply plugin: 'io.codearte.nexus-staging'


nexusStaging {
if (project.hasProperty("sonatypeUsername")) {
username = project.sonatypeUsername
}
if (project.hasProperty("sonatypePassword")) {
password = project.sonatypePassword
}
repositoryDescription = "Release ${project.group} ${project.version}"
}

// TIP use -PpublishRelease=true to active release behavior regardless of the version
status = project.hasProperty('publishRelease') && project.publishRelease.toBoolean() ?
'release' : ((version == 'unspecified' || version.endsWith('-SNAPSHOT')) ? 'snapshot' : 'release')
Expand Down Expand Up @@ -70,19 +86,11 @@ subprojects {
apply plugin: 'groovy'
apply from: "$rootDir/gradle/providedConfiguration.gradle"

apply from: rootProject.file('gradle/signing.gradle')
if (!it.name.endsWith('itest')) {
apply from: rootProject.file('gradle/publish.gradle')
}
if (statusIsRelease) {
apply from: rootProject.file('gradle/deploy.gradle')
}

status = _status

// NOTE sourceCompatibility & targetCompatibility are set in gradle.properties to meet requirements of Gradle
// Must redefine here to work around a bug in the Eclipse plugin
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8

plugins.withType(JavaPlugin) {
project.tasks.withType(JavaCompile) { task ->
Expand All @@ -100,7 +108,7 @@ subprojects {
mavenLocal()
}

jcenter()
mavenCentral()
}

dependencies {
Expand Down Expand Up @@ -155,6 +163,11 @@ configure(subprojects.findAll {it.name != 'itest'}) {
}
}

java {
withJavadocJar()
withSourcesJar()
}

ext {
// path to use for the prepared jruby gems
preparedGems = new File("$buildDir/preparedGems")
Expand All @@ -176,6 +189,10 @@ configure(subprojects.findAll { it.name != 'itest'}) {
jrubyVersion = jrubyVersion
}

compileJava {
options.release = 8
}

// QUESTION is this the right place to insert this task dependency in the lifecycle?
// IMPORTANT The TMP or TEMP environment variable must be set for the gem install command to work on Windows
processResources.dependsOn jrubyPrepare
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=1.6.0
sourceCompatibility=1.7
targetCompatibility=1.7
sourceCompatibility=1.8
targetCompatibility=1.8
185 changes: 77 additions & 108 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,125 +1,94 @@
// NOTE replace deficient built-in publishing plugin with nebula-publishing,
// which does a better job generating the POM and properly aggregates signature files for upload to Bintray
apply plugin: 'maven-publish'
apply plugin: 'de.marcphilipp.nexus-publish'

def projectMeta = {
resolveStrategy = groovy.lang.Closure.DELEGATE_FIRST
name project.name
description project.description
url 'https://github.com/asciidoctor/asciidoctorj'
inceptionYear '2013'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
issueManagement {
system 'github'
url 'https://github.com/asciidoctor/asciidoctorj-pdf/issues'
}
scm {
url 'https://github.com/asciidoctor/asciidoctorj-pdf'
}
developers {
developer {
id 'asotobu'
name 'Alex Soto Bueno'
email 'asotobu@gmail.com'
timezone '1'
roles {
role 'Project Lead'
}
}
developer {
id 'mojavelinux'
name 'Dan Allen'
email 'dan.j.allen@gmail.com'
timezone '-7'
roles {
role 'Contributor'
publishing {
publications.create(project.ext.publicationName, MavenPublication) {

from components.java

pom {
name = project.name
description = project.description
url = 'https://github.com/asciidoctor/asciidoctorj-pdf'
inceptionYear = '2013'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
}
developer {
id 'abelsromero'
name 'Abel Salgado Romero'
email 'abelromero@gmail.com'
timezone '1'
roles {
role 'Contributor'
issueManagement {
system = 'github'
url = 'https://github.com/asciidoctor/asciidoctorj-pdf/issues'
}
}
developer {
id 'robertpanzer'
name 'Robert Panzer'
email 'robert.panzer.pb@gmail.com'
timezone '1'
roles {
role 'Contributor'
scm {
url = 'https://github.com/asciidoctor/asciidoctorj-pdf'
}
}
}
}

afterEvaluate {
publishing.publications {
jars(MavenPublication) {

// NOTE only build sources and javadoc jars when releasing
if (project.statusIsRelease) {
if (project.tasks.withType(Jar).findByName('sourcesJar')) {
artifact sourcesJar
developers {
developer {
id = 'asotobu'
name = 'Alex Soto Bueno'
email = 'asotobu@gmail.com'
timezone = '1'
roles = ['Project Lead']
}
if (project.tasks.withType(Jar).findByName('javadocJar')) {
artifact javadocJar
developer {
id = 'mojavelinux'
name = 'Dan Allen'
email = 'dan.j.allen@gmail.com'
timezone = '-7'
roles = ['Contributor']
}
developer {
id = 'abelsromero'
name = 'Abel Salgado Romero'
email = 'abelromero@gmail.com'
timezone = '1'
roles = ['Contributor']
}
developer {
id = 'robertpanzer'
name = 'Robert Panzer'
email = 'robert.panzer.pb@gmail.com'
timezone = '1'
roles = ['Contributor']
}
}

pom.withXml {
asNode().children().last() + projectMeta
}

from components.java
}
}
}

if ( !project.hasProperty('skip.signing') ) {
task addSignaturesToPublication(dependsOn: signArchives) {
group "publishing"
description "add all signatures to the publication"
// QUESTION should we move manifest creation to general Java plugin config?
jar {
manifest {
attributes \
'Built-By': System.properties['user.name'],
'Created-By': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})".toString(),
'Build-Date': buildDateOnly,
//'Build-Time': buildTimeOnly,
//'Specification-Title': project.name,
//'Specification-Version': project.version,
//'Specification-Vendor': 'asciidoctor.org',
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': 'asciidoctor.org'
}
}

doLast {
publishing.publications {
jars(MavenPublication) {
configurations.signatures.getArtifacts().each { sig ->
logger.debug "adding signature to jars publication: $sig"
artifact(sig) {
extension "jar.asc"
}
}
}
}
publishing {
repositories {
maven {
name = "local"
// change URLs to point to your repos, e.g. http://my.org/repo
def releasesRepoUrl = "${rootProject.buildDir}/repos/releases"
def snapshotsRepoUrl = "${rootProject.buildDir}/repos/snapshots"
url = version.endsWith("SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl
}
}

tasks["signPom"].finalizedBy addSignaturesToPublication
}

// QUESTION should we move manifest creation to general Java plugin config?
jar {
manifest {
attributes \
'Built-By': System.properties['user.name'],
'Created-By': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})".toString(),
'Build-Date': buildDateOnly,
//'Build-Time': buildTimeOnly,
//'Specification-Title': project.name,
//'Specification-Version': project.version,
//'Specification-Vendor': 'asciidoctor.org',
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': 'asciidoctor.org'
}
nexusPublishing {
repositories {
sonatype()
}
}
71 changes: 15 additions & 56 deletions gradle/signing.gradle
Original file line number Diff line number Diff line change
@@ -1,60 +1,19 @@
if ( !project.hasProperty('skip.signing') ){
def hasSigningKey = project.hasProperty("signing.keyId") || project.findProperty("signingKey")
if(hasSigningKey && !project.hasProperty('skip.signing')) {
apply plugin: 'signing'

signing {
sign configurations.archives
}

if ( !signing.signatory ) {
logger.warn "No Signatory configured for project $project.name. Skip signing! See https://docs.gradle.org/current/userguide/signing_plugin.html"
signArchives.enabled = false
ext."skip.signing" = true
}

task signPom(type: Sign) {
group "publishing"
description "Sign the projects pom file"

ext.pom = file("$buildDir/publications/jars/pom-default.xml")
ext.signedPom = file("$buildDir/publications/jars/${project.name}-${project.version}.pom.asc")
ext.bintrayDestination = "${project.group.replace(".","/")}/${project.name}/${project.version}"

inputs.file pom
outputs.file signedPom

doLast{

def input = pom.newInputStream()
def output = signedPom.newOutputStream()
try{
signatory.sign(input, output)
}
catch (Exception e){
logger.error e.message
}
finally {
input.close()
output.close()
}
}
}

/**
* The signPom Task depends on the GenerateMavenPom task which gets dynamically added
* with a name derived from a publication. In our case 'jars'.
*
* Our jars publication registers the signed pom as artifact.
* If the task does not run before publishJarsPublicationToMavenLocal this task will fail.
*/
tasks.whenTaskAdded {

switch (it.name) {
case "generatePomFileForJarsPublication":
signPom.dependsOn it
break
case "publishJarsPublicationToMavenLocal":
it.dependsOn signPom
break
sign(project)
}
void sign(Project project) {
project.signing {
required { project.gradle.taskGraph.hasTask("required") }
def signingKeyId = project.findProperty("signingKeyId")
def signingKey = project.findProperty("signingKey")
def signingPassword = project.findProperty("signingPassword")
if (signingKeyId) {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
} else if (signingKey) {
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign publishing.publications[project.ext.publicationName]
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
Loading

0 comments on commit cf62c61

Please sign in to comment.