Skip to content

Commit e4caabb

Browse files
committed
Set up Maven publishing
1 parent ce856d4 commit e4caabb

2 files changed

Lines changed: 93 additions & 13 deletions

File tree

.github/workflows/build.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@ jobs:
3939
uses: softprops/action-gh-release@v1
4040

4141
# Publish
42-
# - name: Publish packages (GitHub)
43-
# if: github.event_name == 'push' && !startsWith(github.ref_name, 'renovate/')
44-
# run: gradle publishMavenPublicationToGitHubRepository
45-
# env:
46-
# GITHUB_TOKEN: ${{github.token}}
47-
# - name: Publish packages (Maven Central)
48-
# if: github.ref_type == 'tag'
49-
# run: gradle publishToSonatype closeAndReleaseSonatypeStagingRepository
50-
# env:
51-
# SIGNING_KEY: ${{secrets.SIGNING_KEY}}
52-
# SIGNING_PASSWORD: ${{secrets.SIGNING_PASSWORD}}
53-
# SONATYPE_USERNAME: ${{secrets.SONATYPE_USERNAME}}
54-
# SONATYPE_PASSWORD: ${{secrets.SONATYPE_PASSWORD}}
42+
- name: Publish packages (GitHub)
43+
if: github.event_name == 'push' && !startsWith(github.ref_name, 'renovate/')
44+
run: gradle publishAllPublicationsToGitHubRepository
45+
env:
46+
GITHUB_ACTOR: ${{github.actor}}
47+
GITHUB_TOKEN: ${{github.token}}
48+
- name: Publish packages (Maven Central)
49+
if: github.ref_type == 'tag'
50+
run: gradle publishToSonatype closeAndReleaseSonatypeStagingRepository
51+
env:
52+
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
53+
SIGNING_PASSWORD: ${{secrets.SIGNING_PASSWORD}}
54+
SONATYPE_USERNAME: ${{secrets.SONATYPE_USERNAME}}
55+
SONATYPE_PASSWORD: ${{secrets.SONATYPE_PASSWORD}}
5556
- name: Publish documentation
5657
if: github.ref_type == 'tag'
5758
uses: peaceiris/actions-gh-pages@v3

build.gradle.kts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ plugins {
77
kotlin("plugin.serialization") version "2.3.10" apply false
88
id("org.jetbrains.dokka") version "2.1.0"
99
id("org.jetbrains.dokka-javadoc") version "2.1.0"
10+
id("signing")
11+
id("maven-publish")
12+
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
1013
}
1114

1215
subprojects {
@@ -20,6 +23,8 @@ subprojects {
2023
apply(plugin = kotlin("plugin.serialization"))
2124
apply(plugin = "org.jetbrains.dokka")
2225
apply(plugin = "org.jetbrains.dokka-javadoc")
26+
apply(plugin = "signing")
27+
apply(plugin = "maven-publish")
2328

2429
kotlin {
2530
compilerOptions.allWarningsAsErrors = true
@@ -41,6 +46,80 @@ subprojects {
4146
}
4247
}
4348
}
49+
50+
java {
51+
withSourcesJar()
52+
withJavadocJar()
53+
}
54+
55+
tasks.named<Jar>("javadocJar") {
56+
from(tasks.named("dokkaGenerate"))
57+
}
58+
59+
configure<PublishingExtension> {
60+
publications {
61+
create<MavenPublication>("maven") {
62+
from(components["java"])
63+
64+
pom {
65+
name.set(project.name)
66+
description.set("TypedRest helps you build type-safe, fluent-style REST API clients.")
67+
url.set("https://typedrest.net/")
68+
69+
licenses {
70+
license {
71+
name.set("MIT License")
72+
url.set("https://opensource.org/licenses/MIT")
73+
}
74+
}
75+
76+
developers {
77+
developer {
78+
name.set("Bastian Eicher")
79+
url.set("https://github.com/bastianeicher")
80+
}
81+
}
82+
83+
scm {
84+
connection.set("scm:git:https://github.com/TypedRest/TypedRest-Java.git")
85+
developerConnection.set("scm:git:git@github.com:TypedRest/TypedRest-Java.git")
86+
url.set("https://github.com/TypedRest/TypedRest-Java")
87+
}
88+
}
89+
}
90+
}
91+
92+
repositories {
93+
maven {
94+
name = "GitHub"
95+
url = uri("https://maven.pkg.github.com/TypedRest/TypedRest-Java")
96+
credentials {
97+
username = System.getenv("GITHUB_ACTOR")
98+
password = System.getenv("GITHUB_TOKEN")
99+
}
100+
}
101+
}
102+
}
103+
104+
configure<SigningExtension> {
105+
val signingKey = System.getenv("SIGNING_KEY")
106+
val signingPassword = System.getenv("SIGNING_PASSWORD")
107+
if (signingKey != null && signingPassword != null) {
108+
useInMemoryPgpKeys(signingKey, signingPassword)
109+
sign(the<PublishingExtension>().publications["maven"])
110+
}
111+
}
112+
}
113+
114+
nexusPublishing {
115+
repositories {
116+
sonatype {
117+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
118+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
119+
username.set(System.getenv("SONATYPE_USERNAME"))
120+
password.set(System.getenv("SONATYPE_PASSWORD"))
121+
}
122+
}
44123
}
45124

46125
dependencies {

0 commit comments

Comments
 (0)