Skip to content

Commit 580a2ce

Browse files
authored
[ACL-296] Move publishing to Maven Central (#367)
1 parent 398daae commit 580a2ce

File tree

8 files changed

+84
-90
lines changed

8 files changed

+84
-90
lines changed

.github/workflows/release-snapshot.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# Reusable workflow to release to Nexus snapshot repository, referenced by workflow-*.yml pipelines.
2-
name: Release to Nexus snapshots repository
1+
# Reusable workflow to release to Maven Central, referenced by workflow-*.yml pipelines.
2+
name: Release to Maven Central
3+
permissions:
4+
contents: read
35

46
on:
57
workflow_call:
@@ -13,14 +15,18 @@ on:
1315
required: true
1416
type: string
1517
secrets:
16-
sonatype_username:
18+
maven_central_username:
1719
required: true
18-
sonatype_password:
20+
maven_central_password:
21+
required: true
22+
maven_central_signing_key:
23+
required: true
24+
maven_central_signing_key_password:
1925
required: true
2026

2127
jobs:
2228
release-snapshot:
23-
name: Release to Nexus snapshots repository
29+
name: Release to Maven Central
2430
runs-on: ubuntu-latest
2531
steps:
2632
- uses: actions/checkout@v4
@@ -49,8 +55,10 @@ jobs:
4955
else
5056
echo "Project version ${{env.project_version_snapshot}} is not valid"; exit 1;
5157
fi
52-
- name: Publish to Sonatype snapshot repository
53-
run: ./gradlew -Pversion=${{env.project_version_snapshot}} publishToSonatype
58+
- name: Publish snapshot to Maven Central
59+
run: ./gradlew -Pversion=${{env.project_version_snapshot}} publishToMavenCentral
5460
env:
55-
SONATYPE_USERNAME: ${{ secrets.sonatype_username }}
56-
SONATYPE_PASSWORD: ${{ secrets.sonatype_password }}
61+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.maven_central_username }}
62+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.maven_central_password }}
63+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.maven_central_signing_key }}
64+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.maven_central_signing_key_password }}

.github/workflows/workflow-branch.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Build, test, run coverage analysis and release to Maven Central a final release.
44
name: Workflow on internal branch, excluding main
55

6+
permissions:
7+
contents: read
8+
packages: write
9+
610
on:
711
push:
812
branches-ignore:
@@ -34,5 +38,7 @@ jobs:
3438
checkout_ref: ${{ github.ref }}
3539
project_version: ${{ needs.build-test-coverage.outputs.project_version }}
3640
secrets:
37-
sonatype_username: ${{ secrets.SONATYPE_USERNAME }}
38-
sonatype_password: ${{ secrets.SONATYPE_PASSWORD }}
41+
maven_central_username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
42+
maven_central_password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
43+
maven_central_signing_key: ${{ secrets.PGP_SIGNING_IN_MEMORY_KEY }}
44+
maven_central_signing_key_password: ${{ secrets.PGP_SIGNING_IN_MEMORY_KEY_PASSWORD }}

.github/workflows/workflow-main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
steps:
3535
- uses: actions/checkout@v4
3636
with:
37-
checkout_ref: ${{ github.ref }}
37+
ref: ${{ github.ref }}
3838
- name: Setup JDK
3939
uses: actions/setup-java@v4
4040
with:
@@ -55,10 +55,10 @@ jobs:
5555
with:
5656
tag_name: ${{ steps.create_tag.outputs.new_tag }}
5757
generate_release_notes: true
58-
- name: Publish to Sonatype and Maven Central
59-
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
58+
- name: Publish to Maven Central
59+
run: ./gradlew publishToMavenCentral
6060
env:
61-
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
62-
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
63-
SONATYPE_GPG_KEY: ${{ secrets.SONATYPE_GPG_KEY }}
64-
SONATYPE_GPG_PASSPHRASE: ${{ secrets.SONATYPE_GPG_PASSPHRASE }}
61+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
62+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
63+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.PGP_SIGNING_IN_MEMORY_KEY }}
64+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.PGP_SIGNING_IN_MEMORY_KEY_PASSWORD }}

.github/workflows/workflow-pr-fork.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@ jobs:
5252
checkout_ref: ${{ github.event.pull_request.head.sha }}
5353
project_version: ${{ needs.build-test-coverage.outputs.project_version }}
5454
secrets:
55-
sonatype_username: ${{ secrets.SONATYPE_USERNAME }}
56-
sonatype_password: ${{ secrets.SONATYPE_PASSWORD }}
55+
maven_central_username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
56+
maven_central_password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
57+
maven_central_signing_key: ${{ secrets.PGP_SIGNING_IN_MEMORY_KEY }}
58+
maven_central_signing_key_password: ${{ secrets.PGP_SIGNING_IN_MEMORY_KEY_PASSWORD }}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ To use on of those release with Gradle, make sure you have the following reposit
3737
repositories {
3838
// ... all your existing repos here
3939
40-
maven{
41-
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
42-
}
40+
maven {
41+
url = 'https://central.sonatype.com/repository/maven-snapshots/'
42+
}
4343
}
4444
```
4545

build.gradle

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
import com.vanniktech.maven.publish.JavaLibrary
2+
import com.vanniktech.maven.publish.JavadocJar
3+
14
plugins {
25
id 'java-library'
36
// to unleash the lombok magic
47
id "io.freefair.lombok" version "8.13.1"
58
// to make our tests output more fancy
69
id 'com.adarshr.test-logger' version '4.0.0'
7-
// to publish packages
8-
id 'maven-publish'
910
// code linting
1011
id "com.diffplug.spotless" version "7.0.3"
1112
// test coverage
1213
id 'jacoco'
1314
id 'com.github.kt3k.coveralls' version '2.12.2'
14-
// signing
15-
id "signing"
16-
// nexus publishing
17-
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
15+
// maven central publishing
16+
id "com.vanniktech.maven.publish" version "0.34.0"
1817
}
1918

2019
compileJava {
@@ -28,7 +27,8 @@ spotless {
2827
}
2928
}
3029

31-
task createProperties(dependsOn: processResources) {
30+
tasks.register('createProperties') {
31+
dependsOn processResources
3232
doLast {
3333
file("${layout.buildDirectory.get()}/resources/main/truelayer-java.version.properties").withWriter { w ->
3434
Properties p = new Properties()
@@ -147,66 +147,45 @@ jacocoTestReport {
147147
}
148148
}
149149

150-
task sourcesJar(type: Jar) {
150+
tasks.register('sourcesJar', Jar) {
151151
from sourceSets.main.allJava
152152
archiveClassifier = 'sources'
153153
}
154154

155-
task javadocJar(type: Jar) {
155+
tasks.register('javadocJar', Jar) {
156156
from javadoc
157157
archiveClassifier = 'javadoc'
158158
}
159159

160-
publishing {
161-
publications {
162-
mavenJava(MavenPublication) {
163-
from(components.java)
164-
artifact sourcesJar
165-
artifact javadocJar
166-
167-
pom {
168-
name = project_name
169-
packaging = 'jar'
170-
description = project_description
171-
url = project_url
172-
scm {
173-
connection = project_scm
174-
developerConnection = project_scm
175-
url = project_url
176-
}
177-
licenses {
178-
license {
179-
name = project_license_name
180-
url = project_license_url
181-
}
182-
}
183-
developers {
184-
developer {
185-
id = project_developer
186-
name = project_developer
187-
}
188-
}
189-
}
190-
}
191-
}
192-
}
160+
mavenPublishing {
161+
publishToMavenCentral(true)
162+
signAllPublications()
193163

194-
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
195-
signing {
196-
def signingKey = System.getenv('SONATYPE_GPG_KEY')
197-
def signingPassword = System.getenv('SONATYPE_GPG_PASSPHRASE')
198-
useInMemoryPgpKeys(signingKey, signingPassword)
199-
sign publishing.publications.mavenJava
200-
required { isReleaseVersion && gradle.taskGraph.hasTask("publish") }
201-
}
164+
// Use the sources and javadoc jars
165+
configure(new JavaLibrary(new JavadocJar.Javadoc(), true))
202166

203-
nexusPublishing {
204-
repositories {
205-
sonatype {
206-
nexusUrl = uri(sonatype_repository_url)
207-
snapshotRepositoryUrl = uri(sonatype_snapshot_repository_url)
208-
username = System.getenv("SONATYPE_USERNAME")
209-
password = System.getenv("SONATYPE_PASSWORD")
167+
pom {
168+
name = project_name
169+
packaging = 'jar'
170+
description = project_description
171+
url = project_url
172+
scm {
173+
connection = project_scm
174+
url = project_url
175+
}
176+
licenses {
177+
license {
178+
name = project_license_name
179+
url = project_license_url
180+
distribution = project_license_url
181+
}
182+
}
183+
developers {
184+
developer {
185+
id = developer_name
186+
name = developer_name
187+
url = developer_url
188+
}
210189
}
211190
}
212191
}

examples/quarkus-mvc/src/main/java/com/truelayer/quarkusmvc/services/DonationService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public URI createDonationLink(DonationRequest req) {
6363
throw new RuntimeException(String.format("create payment error: %s", paymentResponse.getError()));
6464
}
6565

66-
return tlClient.hpp()
67-
.getHostedPaymentPageLink(
68-
paymentResponse.getData().getId(),
69-
paymentResponse.getData().getResourceToken(),
70-
URI.create("http://localhost:8080/donations/callback"));
66+
return tlClient.hppLinkBuilder()
67+
.resourceId(paymentResponse.getData().getId())
68+
.resourceToken(paymentResponse.getData().getResourceToken())
69+
.returnUri(URI.create("http://localhost:8080/donations/callback"))
70+
.build();
7171
}
7272
}

gradle.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# Main properties
22
group=com.truelayer
33
archivesBaseName=truelayer-java
4-
version=17.3.0
4+
version=17.3.1
55

66
# Artifacts properties
7-
sonatype_repository_url=https://s01.oss.sonatype.org/service/local/
8-
sonatype_snapshot_repository_url=https://s01.oss.sonatype.org/content/repositories/snapshots/
97
project_name=TrueLayer Java
108
project_description=TrueLayer Java SDK for https://truelayer.com
119
project_url=https://github.com/TrueLayer/truelayer-java
10+
project_scm=scm:git:https://github.com/TrueLayer/truelayer-java.git
1211
project_license_url=https://raw.githubusercontent.com/TrueLayer/truelayer-java/main/LICENSE
1312
project_license_name=MIT License
14-
project_developer=truelayer
15-
project_scm=scm:git:https://github.com/TrueLayer/truelayer-java.git
13+
developer_name=truelayer
14+
developer_url=https://github.com/TrueLayer

0 commit comments

Comments
 (0)