Skip to content

Commit 737f3e9

Browse files
committed
Add GH workflow & adjust build.gradle.kts for publishing to Maven central
1 parent c392c1e commit 737f3e9

File tree

2 files changed

+124
-2
lines changed

2 files changed

+124
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish package to the Maven Central Repository
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
packages: write
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
ref: ${{ github.event.release.tag_name }}
18+
- name: Create GitHub Release
19+
uses: ncipollo/release-action@v1
20+
with:
21+
tag: ${{ github.event.release.tag_name }}
22+
generateReleaseNotes: true
23+
- name: Set up Java for publishing to Maven Central Repository
24+
uses: actions/setup-java@v4
25+
with:
26+
java-version: '17'
27+
distribution: 'temurin'
28+
server-id: ossrh
29+
server-username: OSSRH_USERNAME
30+
server-password: OSSRH_TOKEN
31+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
32+
gpg-passphrase: GPG_PASSPHRASE
33+
- name: Validate Gradle wrapper
34+
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
35+
- name: Publish package
36+
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
37+
with:
38+
arguments: publish
39+
env:
40+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
41+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
42+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

build.gradle.kts

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ plugins {
1212

1313
id("io.spring.dependency-management") version springDependencyManagementVersion
1414
kotlin("jvm") version kotlinVersion
15+
id("java-library")
1516
id("com.adarshr.test-logger") version adarshrTestLoggerVersion
1617
id("jacoco")
1718
id("org.sonarqube") version sonarqubeVersion
19+
id("maven-publish")
20+
id("signing")
1821
}
1922

20-
group = "io.github.tobi.laa"
23+
group = "io.github.tobi-laa"
2124
version = "0.0.1-SNAPSHOT"
2225

2326
java {
2427
sourceCompatibility = JavaVersion.VERSION_17
28+
withJavadocJar()
29+
withSourcesJar()
2530
}
2631

2732
sonar {
@@ -72,4 +77,79 @@ tasks.jacocoTestReport {
7277
reports {
7378
xml.required = true
7479
}
75-
}
80+
}
81+
82+
publishing {
83+
publications {
84+
create<MavenPublication>("mavenJava") {
85+
groupId = "${group}"
86+
artifactId = rootProject.name
87+
version = version
88+
from(components["java"])
89+
versionMapping {
90+
usage("java-api") {
91+
fromResolutionOf("runtimeClasspath")
92+
}
93+
usage("java-runtime") {
94+
fromResolutionResult()
95+
}
96+
}
97+
pom {
98+
name = "${group}:${rootProject.name}"
99+
description = "Integrates embedded-redis with Spring Boot"
100+
url = "https://github.com/tobias-laa/spring-boot-embedded-redis.git"
101+
properties = mapOf(
102+
"myProp" to "value",
103+
"prop.with.dots" to "anotherValue"
104+
)
105+
licenses {
106+
license {
107+
name = "The Apache License, Version 2.0"
108+
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
109+
distribution = "repo"
110+
comments = "A business-friendly OSS license"
111+
}
112+
}
113+
developers {
114+
developer {
115+
id = "tobi-laa"
116+
name = "Tobias Laatsch"
117+
email = "tobias.laatsch@posteo.de"
118+
organizationUrl = "https://github.com/tobias-laa"
119+
}
120+
}
121+
scm {
122+
connection = "scm:git:git@github.com:tobias-laa/spring-boot-embedded-redis.git"
123+
developerConnection = "scm:git:git@github.com:tobias-laa/spring-boot-embedded-redis.git"
124+
url = "https://github.com/tobias-laa/spring-boot-embedded-redis/tree/master"
125+
tag = "HEAD"
126+
}
127+
issueManagement {
128+
system = "GitHub Issues"
129+
url = "https://github.com/tobias-laa/spring-boot-embedded-redis/issues"
130+
}
131+
inceptionYear = "2024"
132+
}
133+
}
134+
}
135+
repositories {
136+
maven {
137+
name = "OSSRH"
138+
val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
139+
val snapshotsRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots")
140+
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
141+
credentials {
142+
username = System.getenv("MAVEN_USERNAME")
143+
password = System.getenv("MAVEN_PASSWORD")
144+
}
145+
}
146+
}
147+
}
148+
149+
signing {
150+
sign(publishing.publications["mavenJava"])
151+
}
152+
153+
tasks.javadoc {
154+
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
155+
}

0 commit comments

Comments
 (0)