Skip to content

Commit 78025fb

Browse files
committed
Add central publish
1 parent 22a2089 commit 78025fb

File tree

4 files changed

+161
-7
lines changed

4 files changed

+161
-7
lines changed

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish To Maven Central
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
permissions: write-all
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up JDK 8
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '8'
19+
distribution: 'temurin'
20+
- name: Setup Gradle
21+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
22+
23+
- name: Add permissons
24+
run: chmod +x gradlew
25+
26+
- name: Publish to central
27+
run: ./gradlew clean sonatypeCentralUpload -xtest
28+
env:
29+
CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
30+
CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }}
31+
CENTRAL_PRIVATE_KEY: ${{ secrets.CENTRAL_PRIVATE_KEY }}
32+
CENTRAL_PRIVATE_KEY_PWD: ${{ secrets.CENTRAL_PRIVATE_KEY_PWD }}
33+
CENTRAL_PUBLIC_KEY: ${{ secrets.CENTRAL_PUBLIC_KEY }}

build.gradle.kts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
`java-library`
33
`maven-publish`
4+
id("publish-conventions")
45
}
56

67
repositories {
@@ -16,7 +17,7 @@ dependencies {
1617
compileOnly("org.jetbrains:annotations:23.0.0")
1718
}
1819

19-
group = "snw"
20+
group = "io.github.snwcreations"
2021
version = "0.54.1"
2122
description = "JKook"
2223

@@ -28,12 +29,6 @@ java {
2829
withJavadocJar()
2930
}
3031

31-
publishing {
32-
publications.create<MavenPublication>("maven") {
33-
from(components["java"])
34-
}
35-
}
36-
3732
tasks.compileJava {
3833
options.encoding = "UTF-8"
3934
}

buildSrc/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}
8+
9+
dependencies {
10+
implementation("net.kyori:indra-common:3.1.3")
11+
implementation("cl.franciscosolis.sonatype-central-upload:cl.franciscosolis.sonatype-central-upload.gradle.plugin:1.0.3")
12+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import groovy.util.Node
2+
import groovy.util.NodeList
3+
4+
plugins {
5+
`maven-publish`
6+
`java-library`
7+
id("net.kyori.indra")
8+
id("net.kyori.indra.publishing")
9+
id("cl.franciscosolis.sonatype-central-upload")
10+
}
11+
12+
indra {
13+
github("SNWCreations", "JKook") {
14+
ci(true)
15+
}
16+
apache2License()
17+
18+
javaVersions {
19+
target(8)
20+
minimumToolchain(17)
21+
}
22+
23+
configurePublications {
24+
pom {
25+
url = "https://github.com/SNWCreations/JKook"
26+
description = "The Kook (https://kookapp.cn) Bot's Plugin framework for Java."
27+
developers {
28+
developer {
29+
id = "SNWCreations"
30+
name = "SNWCreations"
31+
email = "snwcreations@qq.com"
32+
roles = listOf("contributor")
33+
}
34+
developer {
35+
id = "huanmeng-qwq"
36+
name = "huanmeng_qwq"
37+
email = "huanmeng@huanmeng-qwq.com"
38+
roles = listOf("contributor")
39+
}
40+
developer {
41+
id = "xiaoACE6716"
42+
name = "xiaoACE"
43+
roles = listOf("contributor")
44+
}
45+
developer {
46+
id = "RealSeek"
47+
name = "RealSeek"
48+
roles = listOf("contributor")
49+
}
50+
developer {
51+
id = "gehongyan"
52+
name = "Ge"
53+
roles = listOf("contributor")
54+
}
55+
developer {
56+
id = "DeeChael"
57+
name = "Deerio Chaelingo"
58+
roles = listOf("contributor")
59+
}
60+
developer {
61+
id = "natholdallas"
62+
name = "natholdallas"
63+
roles = listOf("contributor")
64+
}
65+
}
66+
withXml {
67+
project.configurations.compileOnly.get().allDependencies.forEach { dep ->
68+
((asNode().get("dependencies") as NodeList)[0] as Node).appendNode("dependency").apply {
69+
appendNode("groupId", dep.group)
70+
appendNode("artifactId", dep.name)
71+
appendNode("version", dep.version)
72+
appendNode("scope", "provided")
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
80+
tasks.withType<JavaCompile>().configureEach {
81+
options.compilerArgs = mutableListOf("-Xlint:-deprecation,-unchecked")
82+
}
83+
84+
val cleanUpload by tasks.creating(Delete::class) {
85+
setDelete(project.files(project.layout.buildDirectory.dir("sonatype-central-upload")))
86+
}
87+
88+
tasks.sonatypeCentralUpload {
89+
// gradle sonatypeCentralUpload -PCENTRAL_USERNAME=<username> -PCENTRAL_PASSWORD=<password> -PCENTRAL_PRIVATE_KEY=<privateKey> -PCENTRAL_PRIVATE_KEY_PWD=<privateKeyPwd> -PCENTRAL_PUBLIC_KEY=<publicKey>
90+
val centralUsername = System.getenv("CENTRAL_USERNAME") ?: findProperty("CENTRAL_USERNAME")?.toString()
91+
val centralPassword = System.getenv("CENTRAL_PASSWORD") ?: findProperty("CENTRAL_PASSWORD")?.toString()
92+
val privateKey = System.getenv("CENTRAL_PRIVATE_KEY") ?: findProperty("CENTRAL_PRIVATE_KEY")?.toString()
93+
val privateKeyPwd = System.getenv("CENTRAL_PRIVATE_KEY_PWD") ?: findProperty("CENTRAL_PRIVATE_KEY_PWD")?.toString()
94+
val publicKey = System.getenv("CENTRAL_PUBLIC_KEY") ?: findProperty("CENTRAL_PUBLIC_KEY")?.toString()
95+
dependsOn(tasks.build, tasks.generatePomFileForMavenPublication, cleanUpload)
96+
// this.username = centralUsername
97+
// this.password = centralPassword
98+
this.publishingType = "AUTOMATIC" // MANUAL
99+
this.signingKey = privateKey
100+
this.signingKeyPassphrase = privateKeyPwd
101+
this.publicKey = publicKey
102+
archives = project.layout.buildDirectory.dir("libs").get().asFileTree
103+
pom = file(project.layout.buildDirectory.file("publications/maven/pom-default.xml"))
104+
}
105+
106+
tasks.test {
107+
onlyIf { !gradle.startParameter.taskNames.contains("sonatypeCentralUpload") }
108+
}
109+
110+
project.afterEvaluate {
111+
tasks.findByName("shadowJar")?.apply {
112+
onlyIf { !gradle.startParameter.taskNames.contains("sonatypeCentralUpload") }
113+
}
114+
}

0 commit comments

Comments
 (0)