Skip to content

Commit 02f3727

Browse files
authored
Set up publishing to Maven Central (#74)
Closes #53 and implements proper signing. --- #53 Currently, the library is "deployed" to JitPack. Maven Central was already a desire, but JitPack is actually breaking test fixtures variant in the library's Gradle Module Metadata. As a result, no one can consume the fixtures artifact. - https://jitpack.io/com/github/gabrielfeo/gradle-enterprise-api-kotlin/0.16.0-beta/gradle-enterprise-api-kotlin-0.16.0-beta.module - https://gradle-community.slack.com/archives/CAHSN3LDN/p1683828623398169
1 parent bc569c2 commit 02f3727

File tree

5 files changed

+130
-15
lines changed

5 files changed

+130
-15
lines changed

.github/actions/build/action.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ inputs:
1010
path-to-upload:
1111
description: "Path to upload as artifact"
1212
required: false
13+
dry-run:
14+
description: "Whether to --dry-run"
15+
type: boolean
16+
default: false
1317
runs:
1418
using: "composite"
1519
steps:
@@ -20,12 +24,18 @@ runs:
2024
java-version: 8
2125
- name: Validate Gradle wrapper JAR
2226
uses: gradle/[email protected]
23-
- name: Run Gradle
27+
- name: Set up Gradle
2428
uses: gradle/[email protected]
25-
with:
26-
arguments: ${{ inputs.args }}
29+
- name: Run Gradle
30+
shell: bash
31+
run: |
32+
if [[ "${{ inputs.dry-run }}" == "true" ]]; then
33+
gradle --dry-run ${{ inputs.args }}
34+
else
35+
gradle ${{ inputs.args }}
36+
fi
2737
- name: Upload
28-
if: ${{ inputs.path-to-upload }}
38+
if: ${{ inputs.path-to-upload && !inputs.dry-run }}
2939
uses: actions/[email protected]
3040
with:
3141
name: ${{ inputs.artifact-name }}

.github/workflows/pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ jobs:
7979
with:
8080
dry_run: true
8181

82+
dry-run-publish-library:
83+
uses: ./.github/workflows/publish-library.yml
84+
with:
85+
dry_run: true
86+
8287
dry-run-update-api-spec:
8388
uses: ./.github/workflows/update-api-spec.yml
8489
with:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: 'Publish library to Central'
2+
3+
on:
4+
push:
5+
tags: ['*']
6+
workflow_dispatch:
7+
inputs:
8+
dry_run:
9+
description: 'Dry run'
10+
type: boolean
11+
required: false
12+
workflow_call:
13+
inputs:
14+
dry_run:
15+
description: 'Dry run'
16+
type: boolean
17+
required: true
18+
19+
defaults:
20+
run:
21+
shell: bash
22+
23+
jobs:
24+
25+
build-and-publish:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
- name: gradle publishLibraryPublicationToMavenCentralRepository
31+
uses: ./.github/actions/build
32+
with:
33+
dry-run: ${{ inputs.dry_run }}
34+
args: >-
35+
publishLibraryPublicationToMavenCentralRepository
36+
--rerun-tasks
37+
'-Pversion=${{ github.ref_name }}'
38+
'-Pmaven.central.username=${{ secrets.MAVEN_CENTRAL_USERNAME }}'
39+
'-Pmaven.central.password=${{ secrets.MAVEN_CENTRAL_PASSWORD }}'
40+
'-Psigning.password=${{ secrets.GPG_PASSWORD }}'
41+
'-Psigning.secretKey=${{ secrets.GPG_SECRET_KEY }}'
42+
artifact-name: 'outputs'
43+
path-to-upload: |
44+
library/build/*-api.yaml
45+
library/build/generated/open-api-generator/**/*
46+
library/build/publications/**/*
47+
library/build/libs/**/*

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ org.gradle.caching=true
33
version=SNAPSHOT
44
# Must be later than 2022.1
55
gradle.enterprise.version=2022.4
6-
group=com.github.gabrielfeo
6+
group=com.gabrielfeo
77
artifact=gradle-enterprise-api-kotlin

library/build.gradle.kts

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ plugins {
1111
`java-library`
1212
`java-test-fixtures`
1313
`maven-publish`
14+
`signing`
1415
}
1516

1617
val repoUrl = "https://github.com/gabrielfeo/gradle-enterprise-api-kotlin"
@@ -172,15 +173,6 @@ tasks.named<Jar>("javadocJar") {
172173
from(tasks.dokkaHtml)
173174
}
174175

175-
publishing {
176-
publications {
177-
create<MavenPublication>("library") {
178-
artifactId = "gradle-enterprise-api-kotlin"
179-
from(components["java"])
180-
}
181-
}
182-
}
183-
184176
testing {
185177
suites {
186178
getByName<JvmTestSuite>("test") {
@@ -192,7 +184,6 @@ testing {
192184
}
193185
register<JvmTestSuite>("integrationTest") {
194186
dependencies {
195-
// implementation(project())
196187
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1")
197188
}
198189
}
@@ -229,3 +220,65 @@ dependencies {
229220
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
230221
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
231222
}
223+
224+
publishing {
225+
publications {
226+
create<MavenPublication>("library") {
227+
artifactId = "gradle-enterprise-api-kotlin"
228+
from(components["java"])
229+
pom {
230+
name.set("Gradle Enterprise API Kotlin")
231+
description.set("A library to use the Gradle Enterprise REST API in Kotlin")
232+
url.set("https://github.com/gabrielfeo/gradle-enterprise-api-kotlin")
233+
licenses {
234+
license {
235+
name.set("MIT")
236+
url.set("https://spdx.org/licenses/MIT.html")
237+
distribution.set("repo")
238+
}
239+
}
240+
developers {
241+
developer {
242+
id.set("gabrielfeo")
243+
name.set("Gabriel Feo")
244+
email.set("[email protected]")
245+
}
246+
}
247+
scm {
248+
val basicUrl = "github.com/gabrielfeo/gradle-enterprise-api-kotlin"
249+
connection.set("scm:git:git://$basicUrl.git")
250+
developerConnection.set("scm:git:ssh://$basicUrl.git")
251+
url.set("https://$basicUrl/")
252+
}
253+
}
254+
}
255+
}
256+
repositories {
257+
maven {
258+
name = "mavenCentral"
259+
val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
260+
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
261+
val isSnapshot = version.toString().endsWith("SNAPSHOT")
262+
url = if (isSnapshot) snapshotsRepoUrl else releasesRepoUrl
263+
authentication {
264+
register<BasicAuthentication>("basic")
265+
}
266+
credentials {
267+
username = project.properties["maven.central.username"] as String?
268+
password = project.properties["maven.central.password"] as String?
269+
}
270+
}
271+
}
272+
}
273+
274+
fun isCI() = System.getenv("CI").toBoolean()
275+
276+
signing {
277+
sign(publishing.publications["library"])
278+
if (isCI()) {
279+
useInMemoryPgpKeys(
280+
project.properties["signing.secretKey"] as String?,
281+
project.properties["signing.password"] as String?,
282+
)
283+
}
284+
}

0 commit comments

Comments
 (0)