Skip to content

Commit dc03a74

Browse files
authored
feat: Publish to maven central (#63)
* feat: Publish to maven central * update build versions (it is still built for java 8) * chore: select correct gradle version * am I getting crazy ? YES * a * s * a * .d * use java 17
1 parent 1891c32 commit dc03a74

4 files changed

Lines changed: 91 additions & 50 deletions

File tree

.github/workflows/build.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,27 @@ jobs:
2323
strategy:
2424
matrix:
2525
# follows https://en.wikipedia.org/wiki/Java_version_history#Release_table
26-
java-versions: ['8', '11', '17', '21']
26+
versions: [
27+
{ java: '11', gradle: '8.14.3' },
28+
{ java: '17', gradle: 'current' },
29+
{ java: '21', gradle: 'current' },
30+
{ java: '25', gradle: 'current' },
31+
]
2732

2833
steps:
2934
- name: Checkout
3035
uses: actions/checkout@v4
3136

32-
- name: Set up Java ${{ matrix.java-versions }}
37+
- name: Set up Java ${{ matrix.versions.java }}
3338
uses: actions/setup-java@v4
3439
with:
35-
java-version: ${{ matrix.java-versions }}
40+
java-version: ${{ matrix.versions.java }}
3641
distribution: 'temurin'
37-
cache: 'gradle'
3842

39-
- name: Build & Test
40-
uses: gradle/gradle-build-action@v3
43+
- name: Setup Gradle ${{ matrix.versions.gradle }}
44+
uses: gradle/actions/setup-gradle@v5
4145
with:
42-
arguments: build test
46+
gradle-version: ${{ matrix.versions.gradle }}
47+
48+
- name: Build & Test
49+
run: gradle build test --stacktrace
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish to Maven Central
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
publish:
10+
name: Publish release
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
19+
with:
20+
java-version: '17'
21+
distribution: 'temurin'
22+
cache: gradle
23+
24+
- name: Publish library to Maven Central
25+
run: ./gradlew :publishAndReleaseToMavenCentral --no-configuration-cache
26+
env:
27+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
28+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
29+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.GPG_KEY_ID }}
30+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_SIGNING_KEY }}
31+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_SIGNING_PASSWORD }}

build.gradle.kts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
import com.vanniktech.maven.publish.SonatypeHost
23

34
plugins {
45
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
@@ -7,7 +8,9 @@ plugins {
78

89
// Apply the java-library plugin for API and implementation separation.
910
`java-library`
10-
`maven-publish`
11+
12+
// maven publishing
13+
id("com.vanniktech.maven.publish") version "0.29.0"
1114
}
1215

1316
// from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8
@@ -75,51 +78,50 @@ java {
7578
}
7679

7780
// Javadocs
78-
val javadocJar = tasks.named<Jar>("javadocJar") {
79-
from(tasks.named("dokkaJavadoc"))
80-
}
81+
// val javadocJar = tasks.named<Jar>("javadocJar") {
82+
// from(tasks.named("dokkaJavadoc"))
83+
// }
84+
85+
86+
mavenPublishing {
87+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
88+
89+
signAllPublications()
90+
91+
coordinates(finalGroup, artifact, finalVersion)
92+
93+
pom {
94+
name.set("TCGdex SDK")
95+
description.set("Communicate with the Open Source TCGdex API in Kotlin/Java using the SDK")
96+
url.set("https://github.com/tcgdex/java-sdk")
97+
inceptionYear.set("2022")
8198

82-
publishing {
83-
publications {
84-
create<MavenPublication>("maven") {
85-
groupId = finalGroup
86-
artifactId = artifact
87-
version = finalVersion
88-
89-
from(components["java"])
90-
91-
pom {
92-
name.set("TCGdex SDK")
93-
description.set("Communicate with the Open Source TCGdex API in Kotlin/Java using the SDK")
94-
url.set("https://github.com/tcgdex/java-sdk")
95-
licenses {
96-
license {
97-
name.set("MIT License")
98-
url.set("https://github.com/tcgdex/java-sdk/blob/master/LICENSE.txt")
99-
}
100-
}
101-
developers {
102-
developer {
103-
id.set("avior")
104-
name.set("Avior")
105-
email.set("contact@tcgdex.net")
106-
}
107-
}
108-
scm {
109-
connection.set("scm:git@github.com:tcgdex/java-sdk.git")
110-
url.set("https://github.com/tcgdex/java-sdk")
111-
}
99+
licenses {
100+
license {
101+
name.set("MIT License")
102+
url.set("https://github.com/tcgdex/java-sdk/blob/master/LICENSE.md")
103+
distribution.set("repo")
112104
}
113105
}
114-
}
115-
repositories {
116-
maven {
117-
name = "GithubPackages"
118-
url = uri("https://maven.pkg.github.com/tcgdex/java-sdk")
119-
credentials {
120-
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
121-
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
106+
107+
developers {
108+
developer {
109+
id.set("avior")
110+
name.set("Avior")
111+
email.set("contact@dze.io")
112+
url.set("https://github.com/Aviortheking")
122113
}
123114
}
115+
116+
scm {
117+
url.set("https://github.com/tcgdex/java-sdk")
118+
connection.set("scm:git:git://github.com/tcgdex/java-sdk.git")
119+
developerConnection.set("scm:git:ssh://git@github.com/tcgdex/java-sdk.git")
120+
}
121+
122+
issueManagement {
123+
system.set("GitHub Issues")
124+
url.set("https://github.com/tcgdex/java-sdk/issues")
125+
}
124126
}
125127
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Wed Mar 11 13:36:49 CET 2026
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)