Skip to content

Commit 89fdd08

Browse files
committed
Update gradle publish plugin
Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
1 parent 57fa0da commit 89fdd08

4 files changed

Lines changed: 63 additions & 63 deletions

File tree

.github/workflows/release_build.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
tags:
66
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
workflow_dispatch: {}
78

89
env:
910
REGISTRY: ghcr.io
@@ -13,23 +14,27 @@ jobs:
1314
publishToMaven:
1415
runs-on: ubuntu-latest
1516
env:
16-
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
17-
NEXUS_TOKEN: ${{ secrets.NEXUS_TOKEN }}
18-
PGP_PRIVATE_KEY: ${{ secrets.PGP_PRIVATE_KEY }}
19-
PGP_KEY_PASSPHRASE: ${{ secrets.PGP_KEY_PASSPHRASE }}
17+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
18+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
19+
20+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.PGP_PRIVATE_KEY }}
21+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.PGP_PASSPHRASE }}
2022
steps:
2123
- name: Checkout code
22-
uses: actions/checkout@v6
24+
uses: actions/checkout@v4
25+
2326
- name: Set up JDK
24-
uses: actions/setup-java@v5
27+
uses: actions/setup-java@v4
2528
with:
2629
java-version: ${{ env.JAVA_VERSION }}
27-
distribution: 'adopt'
28-
- name: Publish to Nexus Maven Repository
29-
run: ./gradlew publish
30+
distribution: 'temurin'
31+
32+
- name: Publish to Maven Central
33+
run: ./gradlew clean check publishToMavenCentral
3034

3135
publishDockerImage:
3236
needs: publishToMaven
37+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
3338
runs-on: ubuntu-latest
3439
permissions:
3540
contents: read

build.gradle

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'com.github.kt3k.coveralls' version '2.12.2'
33
id 'com.google.osdetector' version '1.7.3'
44
id 'jvm-test-suite'
5+
id 'com.vanniktech.maven.publish' version '0.35.0'
56
}
67

78
allprojects {
@@ -28,14 +29,14 @@ subprojects {
2829
}
2930

3031
apply plugin: 'java-library'
31-
apply plugin: 'maven-publish'
32-
apply plugin: 'signing'
32+
33+
// vanniktech plugin (maven-publish + signing)
34+
apply plugin: 'com.vanniktech.maven.publish'
3335

3436
java {
3537
sourceCompatibility = JavaVersion.VERSION_1_8
3638
targetCompatibility = JavaVersion.VERSION_1_8
3739

38-
withJavadocJar()
3940
withSourcesJar()
4041
}
4142

@@ -44,65 +45,52 @@ subprojects {
4445
exclude "**/internal/**"
4546
}
4647

47-
publishing {
48-
repositories {
49-
maven {
50-
credentials {
51-
username = project.properties["mavenDeployUser"] ?: System.getenv("NEXUS_USERNAME")
52-
password = project.properties["mavenDeployPassword"] ?: System.getenv("NEXUS_TOKEN")
48+
// Central Portal + signing configuration
49+
mavenPublishing {
50+
// Credentials come from:
51+
// - ORG_GRADLE_PROJECT_mavenCentralUsername
52+
// - ORG_GRADLE_PROJECT_mavenCentralPassword
53+
publishToMavenCentral()
54+
signAllPublications()
55+
56+
pom {
57+
name.set(project.name)
58+
url.set('https://github.com/spiffe/java-spiffe')
59+
60+
// description is only available after evaluation
61+
afterEvaluate {
62+
if (project.description != null) {
63+
description.set(project.description)
5364
}
54-
url = project.properties["mavenDeployUrl"]
5565
}
56-
}
5766

58-
publications {
59-
mavenJava(MavenPublication) {
60-
groupId project.group
61-
version "${project.version}"
62-
from components.java
63-
64-
pom {
65-
name = project.name
66-
artifactId = project.name
67-
url = 'https://github.com/spiffe/java-spiffe'
68-
afterEvaluate {
69-
// description is not available until evaluated.
70-
description = project.description
71-
}
67+
scm {
68+
connection = 'scm:git:https://github.com/spiffe/java-spiffe.git'
69+
developerConnection = 'scm:git:git@github.com:spiffe/java-spiffe.git'
70+
url = 'https://github.com/spiffe/java-spiffe'
71+
}
7272

73-
scm {
74-
connection = 'scm:git:https://github.com/spiffe/java-spiffe.git'
75-
developerConnection = 'scm:git:git@github.com:spiffe/java-spiffe.git'
76-
url = 'https://github.com/spiffe/java-spiffe'
77-
}
73+
licenses {
74+
license {
75+
name = 'The Apache License, Version 2.0'
76+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
77+
}
78+
}
7879

79-
licenses {
80-
license {
81-
name = 'The Apache License, Version 2.0'
82-
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
83-
}
84-
}
85-
developers {
86-
['maxlambrecht:Max Lambrecht', 'rturner3:Ryan Turner'].each { devData ->
87-
developer {
88-
def devInfo = devData.split(':')
89-
id = devInfo[0]
90-
name = devInfo[1]
91-
url = 'https://github.com/' + devInfo[0]
92-
roles = ["Maintainer"]
93-
}
94-
}
80+
developers {
81+
['maxlambrecht:Max Lambrecht', 'rturner3:Ryan Turner'].each { devData ->
82+
developer {
83+
def devInfo = devData.split(':')
84+
id = devInfo[0]
85+
name = devInfo[1]
86+
url = 'https://github.com/' + devInfo[0]
87+
roles = ["Maintainer"]
9588
}
9689
}
9790
}
9891
}
9992
}
10093

101-
signing {
102-
useInMemoryPgpKeys(System.getenv('PGP_PRIVATE_KEY'), System.getenv('PGP_KEY_PASSPHRASE'))
103-
sign publishing.publications.mavenJava
104-
}
105-
10694
dependencies {
10795
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.19.0'
10896
implementation group: 'commons-validator', name: 'commons-validator', version: "1.10.0"
@@ -134,6 +122,14 @@ subprojects {
134122
}
135123
}
136124
}
125+
126+
afterEvaluate {
127+
// Work around Gradle 8.14.x implicit-dependency validation:
128+
// generateMetadataFileForMavenPublication must run after plainJavadocJar.
129+
tasks.matching { it.name == "generateMetadataFileForMavenPublication" }.configureEach {
130+
dependsOn(tasks.named("plainJavadocJar"))
131+
}
132+
}
137133
}
138134

139135
task jacocoTestReport(type: JacocoReport) {

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
version=0.8.13
2-
mavenDeployUrl=https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2
1+
version=0.0.0-test
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)