diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b1c9f15 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 }} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 1749468..af4a465 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ plugins { `java-library` `maven-publish` + id("publish-conventions") } repositories { @@ -16,7 +17,7 @@ dependencies { compileOnly("org.jetbrains:annotations:23.0.0") } -group = "snw" +group = "io.github.snwcreations" version = "0.54.1" description = "JKook" @@ -28,12 +29,6 @@ java { withJavadocJar() } -publishing { - publications.create("maven") { - from(components["java"]) - } -} - tasks.compileJava { options.encoding = "UTF-8" } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..b70ee56 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -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") +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/publish-conventions.gradle.kts b/buildSrc/src/main/kotlin/publish-conventions.gradle.kts new file mode 100644 index 0000000..6b9893f --- /dev/null +++ b/buildSrc/src/main/kotlin/publish-conventions.gradle.kts @@ -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 = "snwcreations@qq.com" + roles = listOf("contributor") + } + developer { + id = "huanmeng-qwq" + name = "huanmeng_qwq" + email = "huanmeng@huanmeng-qwq.com" + 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().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= -PCENTRAL_PASSWORD= -PCENTRAL_PRIVATE_KEY= -PCENTRAL_PRIVATE_KEY_PWD= -PCENTRAL_PUBLIC_KEY= + 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") } + } +} \ No newline at end of file