Skip to content

Commit dbfdd7a

Browse files
committed
ci: first attempt at publishing to maven central portal
1 parent 79dd122 commit dbfdd7a

File tree

2 files changed

+33
-77
lines changed

2 files changed

+33
-77
lines changed

.github/workflows/publish-release.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ jobs:
2727
password: ${{ secrets.GITHUB_TOKEN }}
2828
- name: Publish artifact
2929
env:
30-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31-
GPG_KEYS: ${{ secrets.GPG_KEYS }}
32-
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
33-
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
34-
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
35-
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
30+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
31+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
32+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.GPG_KEY_NAME }}
33+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }}
34+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEYS }}
3635
# The GITHUB_REF tag comes in the format 'refs/tags/xxx'.
3736
# So if we split on '/' and take the 3rd value, we can get the release name.
3837
run: |
3938
export GPG_TTY=$(tty) && echo "$GPG_KEYS" | gpg --fast-import --batch
4039
NEW_VERSION=$(echo "${GITHUB_REF}" | cut -d "/" -f3)
4140
IMAGE=${IMAGE_NAME}:${NEW_VERSION}
4241
echo "Releasing new version ${NEW_VERSION} of $IMAGE"
43-
./gradlew -Pversion=${NEW_VERSION} publish publishToSonatype closeAndReleaseStagingRepository -Dorg.gradle.internal.publish.checksums.insecure=true --info
42+
./gradlew -Pversion=${NEW_VERSION} publishAllPublicationsToGithubPackagesRepository publishAndReleaseToMavenCentral --no-configuration-cache
4443
./gradlew jib --image="${IMAGE}"

build.gradle.kts

Lines changed: 27 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ val reactorTestVersion = "3.7.9"
1919
val ktorVersion = "2.3.13"
2020
val jsonPathVersion = "2.9.0"
2121

22-
val mavenRepoBaseUrl = "https://oss.sonatype.org"
2322
val mainClassKt = "no.nav.security.mock.oauth2.StandaloneMockOAuth2ServerKt"
2423

2524
plugins {
@@ -31,11 +30,9 @@ plugins {
3130
id("com.google.cloud.tools.jib") version "3.4.5"
3231
id("com.github.johnrengelman.shadow") version "8.1.1"
3332
id("net.researchgate.release") version "3.1.0"
34-
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
33+
id("com.vanniktech.maven.publish") version "0.34.0"
3534
id("org.jetbrains.dokka") version "2.0.0"
3635
`java-library`
37-
`maven-publish`
38-
signing
3936
}
4037

4138
application {
@@ -151,62 +148,37 @@ configurations {
151148
}
152149
}
153150

154-
nexusPublishing {
155-
packageGroup.set("no.nav")
156-
clientTimeout.set(Duration.ofMinutes(2))
157-
repositories {
158-
sonatype {
159-
username.set(System.getenv("SONATYPE_USERNAME"))
160-
password.set(System.getenv("SONATYPE_PASSWORD"))
151+
mavenPublishing {
152+
publishToMavenCentral()
153+
signAllPublications()
154+
coordinates(group.toString(), rootProject.name, version.toString())
155+
156+
pom {
157+
name.set(rootProject.name)
158+
description.set("A simple mock oauth2 server based on OkHttp MockWebServer")
159+
url.set("https://github.com/navikt/${rootProject.name}")
160+
licenses {
161+
license {
162+
name.set("MIT License")
163+
url.set("https://opensource.org/licenses/MIT")
164+
distribution.set("https://opensource.org/licenses/MIT")
165+
}
166+
}
167+
developers {
168+
developer {
169+
organization.set("Nav (Arbeids- og velferdsdirektoratet) - The Norwegian Labour and Welfare Administration")
170+
organizationUrl.set("https://www.nav.no")
171+
}
172+
}
173+
scm {
174+
connection.set("scm:git:git://github.com/navikt/${rootProject.name}.git")
175+
developerConnection.set("scm:git:ssh://github.com/navikt/${rootProject.name}.git")
176+
url.set("https://github.com/navikt/${rootProject.name}")
161177
}
162-
}
163-
164-
transitionCheckOptions {
165-
maxRetries.set(60)
166-
delayBetween.set(Duration.ofMillis(10000))
167178
}
168179
}
169180

170181
publishing {
171-
publications {
172-
create<MavenPublication>("mavenJava") {
173-
artifactId = rootProject.name
174-
from(components["java"])
175-
176-
versionMapping {
177-
usage("java-api") {
178-
fromResolutionOf("runtimeClasspath")
179-
}
180-
181-
usage("java-runtime") {
182-
fromResolutionResult()
183-
}
184-
}
185-
pom {
186-
name.set(rootProject.name)
187-
description.set("A simple mock oauth2 server based on OkHttp MockWebServer")
188-
url.set("https://github.com/navikt/${rootProject.name}")
189-
190-
licenses {
191-
license {
192-
name.set("MIT License")
193-
url.set("https://opensource.org/licenses/MIT")
194-
}
195-
}
196-
developers {
197-
developer {
198-
organization.set("NAV (Arbeids- og velferdsdirektoratet) - The Norwegian Labour and Welfare Administration")
199-
organizationUrl.set("https://www.nav.no")
200-
}
201-
}
202-
scm {
203-
connection.set("scm:git:git://github.com/navikt/${rootProject.name}.git")
204-
developerConnection.set("scm:git:ssh://github.com/navikt/${rootProject.name}.git")
205-
url.set("https://github.com/navikt/${rootProject.name}")
206-
}
207-
}
208-
}
209-
}
210182
repositories {
211183
maven {
212184
name = "GitHubPackages"
@@ -219,15 +191,6 @@ publishing {
219191
}
220192
}
221193

222-
ext["signing.gnupg.keyName"] = System.getenv("GPG_KEY_NAME")
223-
ext["signing.gnupg.passphrase"] = System.getenv("GPG_PASSPHRASE")
224-
ext["signing.gnupg.executable"] = "gpg"
225-
226-
signing {
227-
useGpgCmd()
228-
sign(publishing.publications["mavenJava"])
229-
}
230-
231194
tasks.javadoc {
232195
if (JavaVersion.current().isJava9Compatible) {
233196
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
@@ -277,12 +240,6 @@ tasks.named("dependencyUpdates", DependencyUpdatesTask::class.java).configure {
277240
}
278241
}
279242

280-
tasks.named("useLatestVersions", se.patrikerdes.UseLatestVersionsTask::class.java).configure {
281-
updateBlacklist = listOf(
282-
"io.codearte:nexus-staging"
283-
)
284-
}
285-
286243
// This task is added by Gradle when we use java.withJavadocJar()
287244
tasks.named<Jar>("javadocJar") {
288245
from(tasks.named("dokkaJavadoc"))

0 commit comments

Comments
 (0)