import groovy.xml.XmlParser import groovy.xml.XmlUtil plugins { id("java") id("com.github.johnrengelman.shadow") version "8.1.1" id("maven-publish") id("signing") id("io.github.jeadyx.sonatype-uploader") version "1.0" } group = "cn.lunadeer" version = "2.0.7" java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) withJavadocJar() withSourcesJar() } // utf-8 tasks.withType { options.encoding = "UTF-8" } allprojects { apply(plugin = "java") apply(plugin = "com.github.johnrengelman.shadow") repositories { mavenLocal() mavenCentral() maven("https://oss.sonatype.org/content/groups/public") maven("https://repo.papermc.io/repository/maven-public/") maven("https://jitpack.io") maven("https://repo.codemc.org/repository/maven-public") } dependencies { implementation("org.postgresql:postgresql:42.7.2") implementation("mysql:mysql-connector-java:8.0.33") implementation("com.alibaba:fastjson:2.0.31") implementation("net.kyori:adventure-platform-bukkit:4.3.3") compileOnly("com.github.MilkBowl:VaultAPI:1.7") compileOnly("net.milkbowl.vault:VaultUnlockedAPI:2.2") } tasks.shadowJar { archiveClassifier.set("") archiveVersion.set(project.version.toString()) } } dependencies { implementation(project(":core")) implementation(project(":v1_20_1")) implementation(project(":v1_21")) } tasks.shadowJar { archiveClassifier.set("") archiveVersion.set(project.version.toString()) } publishing { // 配置发布信息,改成适合自己的 publications { create("mavenJava") { artifactId = project.name from(components["java"]) pom { name = project.name description = "lunadeer-minecraft-develop-utils" url = "https://ssl.lunadeer.cn:14446/zhangyuheng/MinecraftPluginUtils" licenses { license { name = "MIT" url = "https://opensource.org/license/mit" } } developers { developer { id = "zhangyuheng" name = "zhangyuheng" email = "zhangyuheng@lunadeer.cn" } } scm { connection = "https://ssl.lunadeer.cn:14446/zhangyuheng/MinecraftPluginUtils.git" developerConnection = "scm:git:ssh://git@ssl.lunadeer.cn:14446/zhangyuheng/MinecraftPluginUtils.git" url = "https://ssl.lunadeer.cn:14446/zhangyuheng/MinecraftPluginUtils" } dependencies { } } } } repositories { maven { name = "project" url = uri(layout.buildDirectory.dir("repo")) // 将要发布的文件夹生成到这个目录 } } } signing { // 文件签名 sign(publishing.publications["mavenJava"]) } // remove subproject dependencies from pom file tasks.named("generatePomFileForMavenJavaPublication") { finalizedBy("removePomDependenciesWithGroupIdMinecraftPluginUtils") } // remove subproject dependencies from pom file tasks.register("removePomDependenciesWithGroupIdMinecraftPluginUtils") { doLast { val pomFile = layout.buildDirectory.file("publications/mavenJava/pom-default.xml") .get().asFile val pom = XmlParser().parse(pomFile) val nodes = pom.children() nodes.forEach { n -> val node = n as groovy.util.Node val name = node.name().toString().substringAfter("{http://maven.apache.org/POM/4.0.0}") if (name == "dependencies") { val depsToRemove = mutableListOf() node.children().forEach { val dependency = it as groovy.util.Node if (dependency.text().contains("MinecraftPluginUtils")) { depsToRemove.add(dependency) } } depsToRemove.forEach { node.children().remove(it) } } } pomFile.writeText(XmlUtil.serialize(pom)) } } sonatypeUploader { dir = layout.buildDirectory.dir("repo/cn").get().asFile.path tokenName = project.findProperty("centralUsername")?.toString() tokenPasswd = project.findProperty("centralPassword")?.toString() } tasks.register("uploadToCentral") { // <<<<<<<<< 上传到 Maven 中央仓库 // 1. clean dependsOn("clean") // 2. publishMavenJavaPublicationToProjectRepository dependsOn("publishMavenJavaPublicationToProjectRepository") // 3. upload dependsOn("1.upload deployment dir") } tasks.register("uploadToLocal") { // <<<<<<<<< 上传到本地仓库 // 1. clean dependsOn("clean") // 2. publishMavenJavaPublicationToProjectRepository dependsOn("publishMavenJavaPublicationToMavenLocal") }