Skip to content

Commit

Permalink
Add central publish
Browse files Browse the repository at this point in the history
  • Loading branch information
huanmeng-qwq committed Jan 10, 2025
1 parent 22a2089 commit 78025fb
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 7 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish To Maven Central

on:
push:
tags:
- '*'
workflow_dispatch:

jobs:
build:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Add permissons
run: chmod +x gradlew

- name: Publish to central
run: ./gradlew clean sonatypeCentralUpload -xtest
env:
CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }}
CENTRAL_PRIVATE_KEY: ${{ secrets.CENTRAL_PRIVATE_KEY }}
CENTRAL_PRIVATE_KEY_PWD: ${{ secrets.CENTRAL_PRIVATE_KEY_PWD }}
CENTRAL_PUBLIC_KEY: ${{ secrets.CENTRAL_PUBLIC_KEY }}
9 changes: 2 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
`java-library`
`maven-publish`
id("publish-conventions")
}

repositories {
Expand All @@ -16,7 +17,7 @@ dependencies {
compileOnly("org.jetbrains:annotations:23.0.0")
}

group = "snw"
group = "io.github.snwcreations"
version = "0.54.1"
description = "JKook"

Expand All @@ -28,12 +29,6 @@ java {
withJavadocJar()
}

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}

tasks.compileJava {
options.encoding = "UTF-8"
}
Expand Down
12 changes: 12 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
}

dependencies {
implementation("net.kyori:indra-common:3.1.3")
implementation("cl.franciscosolis.sonatype-central-upload:cl.franciscosolis.sonatype-central-upload.gradle.plugin:1.0.3")
}
114 changes: 114 additions & 0 deletions buildSrc/src/main/kotlin/publish-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import groovy.util.Node
import groovy.util.NodeList

plugins {
`maven-publish`
`java-library`
id("net.kyori.indra")
id("net.kyori.indra.publishing")
id("cl.franciscosolis.sonatype-central-upload")
}

indra {
github("SNWCreations", "JKook") {
ci(true)
}
apache2License()

javaVersions {
target(8)
minimumToolchain(17)
}

configurePublications {
pom {
url = "https://github.com/SNWCreations/JKook"
description = "The Kook (https://kookapp.cn) Bot's Plugin framework for Java."
developers {
developer {
id = "SNWCreations"
name = "SNWCreations"
email = "[email protected]"
roles = listOf("contributor")
}
developer {
id = "huanmeng-qwq"
name = "huanmeng_qwq"
email = "[email protected]"
roles = listOf("contributor")
}
developer {
id = "xiaoACE6716"
name = "xiaoACE"
roles = listOf("contributor")
}
developer {
id = "RealSeek"
name = "RealSeek"
roles = listOf("contributor")
}
developer {
id = "gehongyan"
name = "Ge"
roles = listOf("contributor")
}
developer {
id = "DeeChael"
name = "Deerio Chaelingo"
roles = listOf("contributor")
}
developer {
id = "natholdallas"
name = "natholdallas"
roles = listOf("contributor")
}
}
withXml {
project.configurations.compileOnly.get().allDependencies.forEach { dep ->
((asNode().get("dependencies") as NodeList)[0] as Node).appendNode("dependency").apply {
appendNode("groupId", dep.group)
appendNode("artifactId", dep.name)
appendNode("version", dep.version)
appendNode("scope", "provided")
}
}
}
}
}
}

tasks.withType<JavaCompile>().configureEach {
options.compilerArgs = mutableListOf("-Xlint:-deprecation,-unchecked")
}

val cleanUpload by tasks.creating(Delete::class) {
setDelete(project.files(project.layout.buildDirectory.dir("sonatype-central-upload")))
}

tasks.sonatypeCentralUpload {
// gradle sonatypeCentralUpload -PCENTRAL_USERNAME=<username> -PCENTRAL_PASSWORD=<password> -PCENTRAL_PRIVATE_KEY=<privateKey> -PCENTRAL_PRIVATE_KEY_PWD=<privateKeyPwd> -PCENTRAL_PUBLIC_KEY=<publicKey>
val centralUsername = System.getenv("CENTRAL_USERNAME") ?: findProperty("CENTRAL_USERNAME")?.toString()
val centralPassword = System.getenv("CENTRAL_PASSWORD") ?: findProperty("CENTRAL_PASSWORD")?.toString()
val privateKey = System.getenv("CENTRAL_PRIVATE_KEY") ?: findProperty("CENTRAL_PRIVATE_KEY")?.toString()
val privateKeyPwd = System.getenv("CENTRAL_PRIVATE_KEY_PWD") ?: findProperty("CENTRAL_PRIVATE_KEY_PWD")?.toString()
val publicKey = System.getenv("CENTRAL_PUBLIC_KEY") ?: findProperty("CENTRAL_PUBLIC_KEY")?.toString()
dependsOn(tasks.build, tasks.generatePomFileForMavenPublication, cleanUpload)
// this.username = centralUsername
// this.password = centralPassword
this.publishingType = "AUTOMATIC" // MANUAL
this.signingKey = privateKey
this.signingKeyPassphrase = privateKeyPwd
this.publicKey = publicKey
archives = project.layout.buildDirectory.dir("libs").get().asFileTree
pom = file(project.layout.buildDirectory.file("publications/maven/pom-default.xml"))
}

tasks.test {
onlyIf { !gradle.startParameter.taskNames.contains("sonatypeCentralUpload") }
}

project.afterEvaluate {
tasks.findByName("shadowJar")?.apply {
onlyIf { !gradle.startParameter.taskNames.contains("sonatypeCentralUpload") }
}
}

0 comments on commit 78025fb

Please sign in to comment.