From 74b31124fdf24252310bb6094cd09e2473462c7d Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Sat, 13 Jul 2024 04:10:18 +0200 Subject: [PATCH] Changed gradle to allow publication to maven central. --- .gitignore | 1 + build.gradle.kts | 124 ++++++++++++++++++++++++++++++++++++++++++++-- gradle.properties | 7 ++- 3 files changed, 128 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 80d6030..5d63f6f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.gradle/ /build/ /out/ +.lastDeploymentsId diff --git a/build.gradle.kts b/build.gradle.kts index 15b24a8..f1b8f5c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,26 @@ +import cn.lalaki.pub.BaseCentralPortalPlusExtension +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { - kotlin("jvm") version "1.9.24" + kotlin("jvm") version "2.0.0" java id("org.jetbrains.dokka").version("1.9.20") - id("com.github.johnrengelman.shadow").version("7.1.2") + id("io.github.goooler.shadow").version("8.1.8") // using fork of com.github.johnrengelman.shadow to support java 1.21 + // Maven publish + `maven-publish` + signing + id("cn.lalaki.central").version("1.2.5") } group = "xyz.alexcrea" version = "1.5.2" +java { + disableAutoTargetJvm() + toolchain.languageVersion.set(JavaLanguageVersion.of(20)) +} + repositories { mavenCentral() maven(url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/") @@ -48,6 +61,20 @@ tasks.getByName("test") { useJUnitPlatform() } +// Set target version +tasks.withType().configureEach { + sourceCompatibility = "16" // We aim for java 16 for minecraft 1.16.5. even if it not really suported. + targetCompatibility = "16" +} + +kotlin { + compilerOptions { + apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0) + jvmTarget.set(JvmTarget.JVM_16) + } +} + + // Fat-jar builder val fatJar = tasks.register("fatJar") { manifest { @@ -65,7 +92,98 @@ tasks.getByName("build") { dependsOn(fatJar) } -// Shadow recesary dependency +// Shadow necessary dependency tasks.shadowJar { relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.inventoryframework") } + +val sourcesJar by tasks.registering(Jar::class) { + archiveClassifier.set("sources") + from(kotlin.sourceSets.main.get().kotlin) +} + +val javadocJar by tasks.creating(Jar::class) { + group = JavaBasePlugin.DOCUMENTATION_GROUP + description = "Assembles Javadoc JAR" + archiveClassifier.set("javadoc") + from(tasks.named("dokkaHtml")) +} + +signing { + useGpgCmd() + val extension = extensions + .getByName("publishing") as PublishingExtension + sign(extension.publications) +} + +// ------------------------------------ +// PUBLISHING TO SONATYPE CONFIGURATION +// ------------------------------------ + +val localMavenRepo = uri("E:\\WorkSpace\\Java\\Maven\\repo") // The path is recommended to be set to an empty directory +centralPortalPlus { + url = localMavenRepo + username = System.getenv("SONATYPE_USERNAME") + password = System.getenv("SONATYPE_PASSWORD") + publishingType = BaseCentralPortalPlusExtension.PublishingType.USER_MANAGED // or PublishingType.AUTOMATIC +} + +object Meta { + const val desc = "spigot plugin to control every aspect of the anvil." + const val license = "GPL-3.0" + const val githubRepo = "alexcrea/CustomAnvil" + const val release = "https://s01.oss.sonatype.org/service/local/" + const val snapshot = "https://s01.oss.sonatype.org/content/repositories/snapshots/" +} + +publishing { + repositories { + maven { + url = localMavenRepo // Specify the same local repo path in the configuration. + } + } + + publications { + create("maven") { + groupId = project.group.toString() + artifactId = project.name + version = project.version.toString() + from(components["kotlin"]) + artifact(tasks["sourcesJar"]) + artifact(tasks["javadocJar"]) + pom { + name.set(project.name) + description.set(Meta.desc) + url.set("https://github.com/${Meta.githubRepo}") + licenses { + license { + name.set(Meta.license) + url.set("https://www.gnu.org/licenses/gpl-3.0.en.html") + } + } + developers { + developer { + id.set("alexcrea") + name.set("alexcrea") + email.set("alexcrea.of@laposte.net") + url.set("https://github.com/alexcrea") + } + } + scm { + url.set( + "https://github.com/${Meta.githubRepo}.git" + ) + connection.set( + "scm:git:git://github.com/${Meta.githubRepo}.git" + ) + developerConnection.set( + "scm:git:git://github.com/${Meta.githubRepo}.git" + ) + } + issueManagement { + url.set("https://github.com/${Meta.githubRepo}/issues") + } + } + } + } +} diff --git a/gradle.properties b/gradle.properties index 29e08e8..a064d6a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,6 @@ -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official + +# Signing +signing.gnupg.executable=gpg +signing.gnupg.useLegacyGpg=true +signing.gnupg.keyName=B0DBF91F \ No newline at end of file