Skip to content

Commit ca142a0

Browse files
committed
Add jreleaser to enable publishing (snapshots) to maven central
Signed-off-by: Wei-Qiang Zhou <wei-qiang.zhou@alliander.com>
1 parent 67a6dbb commit ca142a0

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

‎.github/workflows/java-gradle-ci.yml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,53 @@ jobs:
5151
reuse-compliance:
5252
name: REUSE Compliance
5353
uses: ./.github/workflows/reuse-compliance.yml
54+
55+
push-and-deploy:
56+
name: Push Deployment Updates
57+
needs: [build-and-test]
58+
if: always() && github.ref_type == 'tag'
59+
runs-on: ubuntu-latest
60+
permissions:
61+
id-token: write
62+
contents: read
63+
64+
steps:
65+
- name: Checkout repository
66+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
67+
with:
68+
fetch-depth: 1
69+
persist-credentials: false
70+
71+
- name: Setup runtime
72+
uses: ./.github/actions/setup-runtime
73+
74+
- name: Cache Gradle
75+
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 #v6.1.0
76+
with:
77+
path: |
78+
~/.gradle/caches
79+
~/.gradle/wrapper
80+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/settings.gradle*') }}
81+
82+
- name: Optimize Gradle
83+
shell: bash
84+
run: |
85+
mkdir -p ~/.gradle
86+
echo "org.gradle.caching=true" >> ~/.gradle/gradle.properties
87+
echo "org.gradle.configuration-cache=true" >> ~/.gradle/gradle.properties
88+
89+
- name: Gradle Release Build
90+
env:
91+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
92+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
93+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
94+
SANITIZED_TAG: ${{ github.ref_name }}
95+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVEN_USERNAME }}
96+
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
97+
JRELEASER_NEXUS2_USERNAME: ${{ secrets.MAVEN_USERNAME }}
98+
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
99+
run: |
100+
echo "Performing release Gradle publish for tag: $SANITIZED_TAG"
101+
102+
./gradlew clean build \
103+
jreleaserDeploy --dryrun -jreleaser.project.version=$SANITIZED_TAG

‎build.gradle‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
//
33
// SPDX-License-Identifier: MPL-2.0
44

5+
6+
import org.jreleaser.model.Active
7+
58
import javax.inject.Inject
69

710
plugins {
811
id 'java'
912
id 'maven-publish'
13+
id 'org.jreleaser' version '1.26.0'
1014
}
1115

1216
interface InjectedExecOps {
@@ -268,6 +272,20 @@ sourceSets {
268272
}
269273
}
270274

275+
tasks.register('sourcesJar', Jar) {
276+
dependsOn(tasks.named('generatePGMBindings'))
277+
from sourceSets.main.java
278+
archiveClassifier.set('sources')
279+
}
280+
281+
artifacts {
282+
archives sourcesJar
283+
}
284+
285+
java {
286+
withJavadocJar()
287+
}
288+
271289
tasks.named('compileJava') {
272290
dependsOn(tasks.named('generatePGMBindings'))
273291
}
@@ -280,7 +298,60 @@ publishing {
280298
publications {
281299
mavenJava(MavenPublication) {
282300
from components.java
301+
groupId = 'org.lfenergy.pgm'
283302
artifactId = 'lib-power-grid-model'
303+
304+
pom {
305+
name = 'lib-power-grid-model'
306+
description = ''
307+
url = 'https://github.com/PowerGridModel/libpower-grid-model-java'
308+
organization {
309+
name = 'LF Energy'
310+
url = 'https://lfenergy.org'
311+
}
312+
licenses {
313+
license {
314+
name = 'Mozilla Public License, Version 2.0"'
315+
url = 'https://www.mozilla.org/en-US/MPL/2.0/'
316+
}
317+
}
318+
developers {
319+
developer {
320+
email = 'powergridmodel@lfenergy.org'
321+
}
322+
}
323+
scm {
324+
url = 'https://github.com/PowerGridModel/libpower-grid-model-java'
325+
connection = 'scm:git:git://github.com/PowerGridModel/libpower-grid-model-java.git'
326+
developerConnection = 'scm:git:ssh://git@github.com/PowerGridModel/libpower-grid-model-java.git'
327+
}
328+
}
329+
330+
}
331+
}
332+
}
333+
334+
jreleaser {
335+
signing {
336+
active = 'ALWAYS'
337+
armored = true
338+
}
339+
deploy {
340+
maven {
341+
// mavenCentral {
342+
// 'release-deploy' {
343+
// active = 'RELEASE'
344+
// url = 'https://central.sonatype.com/api/v1/publisher'
345+
// }
346+
// }
347+
nexus2 {
348+
'snapshot-deploy' {
349+
active = 'SNAPSHOT'
350+
snapshotUrl = 'https://central.sonatype.com/repository/maven-snapshots/'
351+
applyMavenCentralRules = true
352+
snapshotSupported = true
353+
}
354+
}
284355
}
285356
}
286357
}

0 commit comments

Comments
 (0)