Skip to content

Commit 125f136

Browse files
committed
ci: release using jreleaser
1 parent 3626aa9 commit 125f136

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
env:
88
ORG_GRADLE_PROJECT_version: ${{ github.event.release.tag_name }}
99
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
10-
GRADLE_OPTS: -Dorg.gradle.configuration-cache=false
1110

1211
jobs:
1312
release:
@@ -30,11 +29,12 @@ jobs:
3029
- name: Release Artefacts
3130
run: ./gradlew release
3231
env:
32+
GRADLE_OPTS: -Dorg.gradle.configuration-cache=false
3333
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PACKAGE_SIGNING_KEY }}
3434
ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.PACKAGE_SIGNING_KEY_PASSWORD }}
3535
ORG_GRADLE_PROJECT_githubToken: ${{ secrets.GITHUB_TOKEN }}
36-
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.OSSRH_USERNAME }}
37-
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }}
36+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
37+
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
3838

3939
docs:
4040
name: Publish Documentation

build.gradle.kts

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import io.github.gradlenexus.publishplugin.NexusRepository
21
import org.gradle.kotlin.dsl.*
2+
import org.jreleaser.model.Active.ALWAYS
3+
34

45
plugins {
56
kotlin("jvm") version "2.2.21"
67
id("org.jetbrains.dokka-javadoc") version "2.1.0"
78
id("org.jetbrains.dokka") version "2.1.0"
89
`maven-publish`
910
signing
10-
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
11+
id("org.jreleaser") version "1.21.0"
1112
}
1213

1314
group = "de.joshuagleitze"
@@ -52,8 +53,7 @@ tasks.withType<Test>().configureEach {
5253
}
5354
}
5455

55-
val ossrhUsername: String? by project
56-
val ossrhPassword: String? by project
56+
5757
val githubRepository: String? by project
5858
val githubOwner = githubRepository?.split("/")?.get(0)
5959
val githubToken: String? by project
@@ -84,7 +84,7 @@ val dokkaJar by tasks.registering(Jar::class) {
8484

8585
lateinit var publication: MavenPublication
8686
lateinit var githubPackages: ArtifactRepository
87-
lateinit var mavenCentral: NexusRepository
87+
lateinit var mavenCentralStaging: MavenArtifactRepository
8888

8989
publishing {
9090
publications {
@@ -128,6 +128,9 @@ publishing {
128128
}
129129
}
130130
repositories {
131+
mavenCentralStaging = maven(layout.buildDirectory.dir("publish/maven-central-staging")) {
132+
name = "MavenCentralStaging"
133+
}
131134
githubPackages = maven("https://maven.pkg.github.com/$githubRepository") {
132135
name = "GitHubPackages"
133136
credentials {
@@ -138,31 +141,41 @@ publishing {
138141
}
139142
}
140143

141-
nexusPublishing {
142-
repositories {
143-
mavenCentral = sonatype {
144-
username = ossrhUsername
145-
password = ossrhPassword
144+
signing {
145+
useInMemoryPgpKeys(
146+
providers.gradleProperty("signingKey").orNull,
147+
providers.gradleProperty("signingKeyPassword").orNull
148+
)
149+
sign(publication)
150+
}
151+
152+
jreleaser {
153+
deploy {
154+
maven {
155+
mavenCentral {
156+
register("sonatype") {
157+
url = "https://central.sonatype.com/api/v1/publisher"
158+
active = ALWAYS
159+
stagingRepository(mavenCentralStaging.url.toString())
160+
}
161+
}
146162
}
147163
}
148164
}
149165

150-
signing {
151-
val signingKey: String? by project
152-
val signingKeyPassword: String? by project
153-
useInMemoryPgpKeys(signingKey, signingKeyPassword)
154-
sign(publication)
155-
}
166+
val jreleaserConfig by tasks
167+
val jreleaserDeploy by tasks
156168

157-
val closeAndReleaseStagingRepositories by project.tasks
158-
closeAndReleaseStagingRepositories.mustRunAfter(mavenCentral.publishTask)
169+
jreleaserDeploy.mustRunAfter(jreleaserConfig)
170+
jreleaserDeploy.mustRunAfter(mavenCentralStaging.publishTask)
159171

160172
val release by tasks.registering {
161173
group = "release"
162-
description = "Releases the project to Maven Central"
163-
dependsOn(githubPackages.publishTask, mavenCentral.publishTask, closeAndReleaseStagingRepositories)
174+
description = "Releases the project to all repositories"
175+
dependsOn(jreleaserConfig, githubPackages.publishTask, mavenCentralStaging.publishTask, jreleaserDeploy)
164176
}
165177

166178
fun String.drop(prefix: String) = if (this.startsWith(prefix)) this.drop(prefix.length) else this
167179
val ArtifactRepository.publishTask get() = tasks["publishAllPublicationsTo${this.name}Repository"]
168-
val NexusRepository.publishTask get() = "publishTo${this.name.replaceFirstChar { it.titlecase() }}"
180+
fun ProviderFactory.requiredGradleProperty(name: String): Provider<String> = gradleProperty(name)
181+
.orElse(provider { throw InvalidUserDataException("required project property `$name` was not set!")})

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
org.gradle.parallel=true
2-
org.gradle.configuration-cache=true
2+
org.gradle.configuration-cache=false
33
org.gradle.configuration-cache.parallel=true
44

55
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled

0 commit comments

Comments
 (0)