From f0583a6706e4084c6eb7b707d7e6279271ef1103 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 14 Apr 2020 15:19:31 +0200 Subject: [PATCH 1/2] gradle: switch to 'maven-publish' plugin It is time to switch from the original, depreacted publishing mechanism based on the 'maven' plugin, to the new mechanism. --- build.gradle | 74 +++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index 8713c27d..fbf325a5 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,7 @@ allprojects { rootConfigDir = new File(rootDir, 'config') gitCommit = getGitCommit() builtDate = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date()) + isContinuousIntegrationEnvironment = Boolean.parseBoolean(System.getenv('CI')) isReleaseVersion = !isSnapshot signingRequired = isReleaseVersion sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword') @@ -94,7 +95,7 @@ allprojects { } subprojects { - apply plugin: 'maven' + apply plugin: 'maven-publish' apply plugin: 'signing' task sourcesJar(type: Jar, dependsOn: classes) { @@ -105,69 +106,64 @@ subprojects { classifier = 'javadoc' from javadoc.destinationDir } - task testJar(type: Jar, dependsOn: testClasses) { + task testsJar(type: Jar, dependsOn: testClasses) { classifier = 'tests' from sourceSets.test.output } - artifacts { - archives sourcesJar - archives javadocJar - archives testJar - } - - uploadArchives { - repositories { - mavenDeployer { - if (signingRequired) { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - } - repository(url: project.sonatypeStagingUrl) { - if (sonatypeCredentialsAvailable) { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - } - snapshotRepository(url: project.sonatypeSnapshotUrl) { - if (sonatypeCredentialsAvailable) { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - } - - pom.project { - name 'PGPainless' + publishing { + publications { + mavenJava(MavenPublication) { + from components.java + artifact sourcesJar + artifact javadocJar + artifact testsJar + pom { + name = 'PGPainless' description 'Simple to use OpenPGP API for Java based on Bouncycastle' - url 'https://github.com/pgpainless/pgpainless' - inceptionYear '2018' + url = 'https://github.com/pgpainless/pgpainless' + inceptionYear = '2018' scm { - url 'https://github.com/pgpainless/pgpainless' - connection 'scm:https://github.com/pgpainless/pgpainless' - developerConnection 'scm:git://github.com/pgpainless/pgpainless.git' + url = 'https://github.com/pgpainless/pgpainless' + connection = 'scm:https://github.com/pgpainless/pgpainless' + developerConnection = 'scm:git://github.com/pgpainless/pgpainless.git' } licenses { license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution = 'repo' } } developers { developer { - id 'vanitasvitae' - name 'Paul Schaub' - email 'vanitasvitae@fsfe.org' + id = 'vanitasvitae' + name = 'Paul Schaub' + email = 'vanitasvitae@fsfe.org' } } } } } + repositories { + if (sonatypeCredentialsAvailable) { + maven { + url isSnapshot ? sonatypeSnapshotUrl : sonatypeStagingUrl + credentials { + username = sonatypeUsername + password = sonatypePassword + } + } + } + } } signing { required { signingRequired } - sign configurations.archives + sign publishing.publications.mavenJava } } From 819847be4b464423612151f3e06f5c464ce9b47b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 14 Apr 2020 15:21:13 +0200 Subject: [PATCH 2/2] gradle: use gpg (agent) for signing --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index fbf325a5..bc1db1ef 100644 --- a/build.gradle +++ b/build.gradle @@ -60,7 +60,7 @@ allprojects { builtDate = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date()) isContinuousIntegrationEnvironment = Boolean.parseBoolean(System.getenv('CI')) isReleaseVersion = !isSnapshot - signingRequired = isReleaseVersion + signingRequired = !(isSnapshot || isContinuousIntegrationEnvironment) sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword') sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots' sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' @@ -162,6 +162,7 @@ subprojects { } signing { + useGpgCmd() required { signingRequired } sign publishing.publications.mavenJava }