From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Kyle Wood Date: Thu, 10 Dec 2020 20:54:19 -0800 Subject: [PATCH] Setup Gradle project The pom.xml file is deleted in this patch so the patch will fail to apply if there are changes made to it from upstream - thus notifying us that changes were made. diff --git a/.gitignore b/.gitignore index 67fb370cad6924895a6b27052dbd5c1767e3f0c9..bb338269c9e3bef4c274157c490d8b8f8c589937 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.gradle/ +build/ + # Eclipse stuff /.classpath /.project @@ -37,3 +40,7 @@ dependency-reduced-pom.xml /src/main/resources/achievement /src/main/resources/lang + +# vs code +/.vscode +/.factorypath diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000000000000000000000000000000000..8dea71d371fb31b50da6b53b0f80030ed1c7c484 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,173 @@ +import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer +import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer +import io.papermc.paperweight.util.Git +import io.papermc.paperweight.util.path +import shadow.org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE +import java.util.Locale + +plugins { + java + `maven-publish` + id("com.github.johnrengelman.shadow") +} + +repositories { + maven("https://libraries.minecraft.net/") +} + +dependencies { + implementation(project(":Paper-API")) + implementation("jline:jline:2.12.1") + implementation("org.apache.logging.log4j:log4j-iostreams:2.14.1") { + exclude(group = "org.apache.logging.log4j", module = "log4j-api") + } + implementation("org.ow2.asm:asm:9.2") + implementation("com.googlecode.json-simple:json-simple:1.1.1") { + // This includes junit transitively for whatever reason + isTransitive = false + } + runtimeOnly("org.xerial:sqlite-jdbc:3.34.0") + runtimeOnly("mysql:mysql-connector-java:5.1.49") + + runtimeOnly("org.apache.maven:maven-resolver-provider:3.8.1") + runtimeOnly("org.apache.maven.resolver:maven-resolver-connector-basic:1.7.0") + runtimeOnly("org.apache.maven.resolver:maven-resolver-transport-http:1.7.0") + + testImplementation("junit:junit:4.13.1") + testImplementation("org.hamcrest:hamcrest-library:1.3") +} + +tasks.jar { + archiveClassifier.set("dev") + + manifest { + val git = Git(rootProject.layout.projectDirectory.path) + val gitHash = git("rev-parse", "--short=7", "HEAD").getText().trim() + val implementationVersion = System.getenv("BUILD_NUMBER") ?: "\"$gitHash\"" + val date = git("show", "-s", "--format=%ci", gitHash).getText().trim() // Paper + attributes( + "Main-Class" to "org.bukkit.craftbukkit.Main", + "Implementation-Title" to "CraftBukkit", + "Implementation-Version" to "git-Paper-$implementationVersion", + "Implementation-Vendor" to date, // Paper + "Specification-Title" to "Bukkit", + "Specification-Version" to project.version, + "Specification-Vendor" to "Bukkit Team", + ) + for (tld in setOf("net", "com", "org")) { + attributes("$tld/bukkit", "Sealed" to true) + } + } +} + +publishing { + publications.create("maven") { + artifactId = rootProject.name.toLowerCase(Locale.ENGLISH) + artifact(tasks.reobfJar) { + classifier = null + } + artifact(tasks.shadowJar) + } +} + +relocation { + // Order matters here - e.g. craftbukkit proper must be relocated before any of the libs are relocated into the cb package + val packageVersion = "1_17_R1" + relocate("org.bukkit.craftbukkit" to "org.bukkit.craftbukkit.v$packageVersion") { + exclude("org.bukkit.craftbukkit.Main*") + } + + fun cb(pack: String) = "org.bukkit.craftbukkit.libs.$pack" + + relocate("org.jline:jline-terminal-jansi", "org.jline" to cb("jline")) + sequenceOf( + "commons-codec:commons-codec" to "org.apache.commons.codec", + "commons-io:commons-io" to "org.apache.commons.io", + "it.unimi.dsi:fastutil" to "it.unimi", + "org.apache.commons:commons-lang3" to "org.apache.commons.lang3", + "org.ow2.asm:asm" to "org.objectweb.asm" + ).forEach { (owner, pack) -> + relocate(owner, pack to cb(pack)) + } + + // runtimeOnly dependencies don't need an owner attached + // owner is used for dev bundle generation, runtimeOnly deps are not included in dev bundle + sequenceOf( + "org.apache.http", + "org.apache.maven", + "org.codehaus.plexus", + "org.eclipse.aether", + "org.eclipse.sisu" + ).forEach { pack -> + relocate(pack to cb(pack)) + } +} + +tasks.shadowJar { + archiveClassifier.set("mojang-mapped") + + for (relocation in relocation.relocations.get()) { + relocate(relocation.fromPackage, relocation.toPackage) { + for (exclude in relocation.excludes) { + exclude(exclude) + } + } + } + mergeServiceFiles() + transform(ModifiedLog4j2PluginsCacheFileTransformer::class.java) +} + +tasks.test { + exclude("org/bukkit/craftbukkit/inventory/ItemStack*Test.class") +} + +fun TaskContainer.registerRunTask( + name: String, block: JavaExec.() -> Unit +): TaskProvider = register(name) { + group = "paper" + standardInput = System.`in` + workingDir = rootProject.layout.projectDirectory.dir( + providers.gradleProperty("runWorkDir").forUseAtConfigurationTime().orElse("run") + ).get().asFile + + if (rootProject.childProjects["test-plugin"] != null) { + val testPluginJar = rootProject.project(":test-plugin").tasks.jar.flatMap { it.archiveFile } + inputs.file(testPluginJar) + args("-add-plugin=${testPluginJar.get().asFile.absolutePath}") + } + + args("--nogui") + systemProperty("net.kyori.adventure.text.warnWhenLegacyFormattingDetected", true) + if (project.hasProperty("disableWatchdog")) { + systemProperty("disable.watchdog", true) + } + doFirst { + workingDir.mkdirs() + } + javaLauncher.set(project.javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(project.tasks.compileJava.get().options.release.get())) + }) + block(this) +} + +tasks.registerRunTask("runShadow") { + description = "Spin up a test server from the shadowJar archiveFile" + classpath(tasks.shadowJar.flatMap { it.archiveFile }) +} + +tasks.registerRunTask("runReobf") { + description = "Spin up a test server from the reobfJar output jar" + classpath(tasks.reobfJar.flatMap { it.outputJar }) +} + +tasks.registerRunTask("runDev") { + description = "Spin up a non-shaded non-remapped test server" + classpath = java.sourceSets.main.get().runtimeClasspath + mainClass.set("org.bukkit.craftbukkit.Main") +} + +class ModifiedLog4j2PluginsCacheFileTransformer : Transformer by Log4j2PluginsCacheFileTransformer() { + override fun canTransformResource(element: FileTreeElement): Boolean { + return PLUGIN_CACHE_FILE == element.name || element.name == "Log4j2Plugins.dat" + } +} diff --git a/pom.xml b/pom.xml deleted file mode 100644 index c936167e107ab76cfb21febb9534353f481a95d3..0000000000000000000000000000000000000000 --- a/pom.xml +++ /dev/null @@ -1,472 +0,0 @@ - - 4.0.0 - org.spigotmc - spigot - jar - 1.17.1-R0.1-SNAPSHOT - Spigot - https://www.spigotmc.org/ - - - true - UTF-8 - unknown - git - 1_17_R1 - 1.8 - 1.8 - - - - org.spigotmc - spigot-parent - dev-SNAPSHOT - ../pom.xml - - - - - org.spigotmc - spigot-api - ${project.version} - compile - - - org.spigotmc - minecraft-server - ${project.version} - compile - - - jline - jline - 2.12.1 - compile - - - org.apache.logging.log4j - log4j-iostreams - 2.14.1 - compile - - - - org.apache.logging.log4j - log4j-api - - - - - org.ow2.asm - asm - 9.2 - compile - - - - com.googlecode.json-simple - json-simple - 1.1.1 - runtime - - - org.xerial - sqlite-jdbc - 3.34.0 - runtime - - - mysql - mysql-connector-java - 5.1.49 - runtime - - - - org.apache.maven - maven-resolver-provider - 3.8.1 - runtime - - - org.apache.maven.resolver - maven-resolver-connector-basic - 1.7.0 - runtime - - - org.apache.maven.resolver - maven-resolver-transport-http - 1.7.0 - runtime - - - - junit - junit - 4.13.1 - test - - - org.hamcrest - hamcrest-library - 1.3 - test - - - - - - - - net.md-5 - scriptus - 0.4.1 - - - ex-spigot - - ${bt.name}-Spigot-%s - ../ - spigot.desc - - initialize - - describe - - - - ex-craftbukkit - - -%s - ../../CraftBukkit - craftbukkit.desc - - initialize - - describe - - - - - - org.apache.maven.plugins - maven-clean-plugin - 3.1.0 - - - initialize - - clean - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.0 - - - - false - - - org.bukkit.craftbukkit.Main - CraftBukkit - ${spigot.desc}${craftbukkit.desc} - ${project.build.outputTimestamp} - Bukkit - ${api.version} - Bukkit Team - true - - - - net/bukkit/ - - true - - - - com/bukkit/ - - true - - - - org/bukkit/ - - true - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - org.ow2.asm - asm - 9.1 - - - org.ow2.asm - asm-commons - 9.1 - - - - - package - - shade - - - ${shadeSourcesJar} - - - org.spigotmc:minecraft-server - - com/google/common/** - com/google/gson/** - com/google/thirdparty/** - - - - org.eclipse.sisu:org.eclipse.sisu.inject - - META-INF/services/javax.annotation.processing.Processor - - - - - - - - jline - org.bukkit.craftbukkit.libs.jline - - - it.unimi - org.bukkit.craftbukkit.libs.it.unimi - - - org.apache.commons.codec - org.bukkit.craftbukkit.libs.org.apache.commons.codec - - - org.apache.commons.io - org.bukkit.craftbukkit.libs.org.apache.commons.io - - - org.apache.commons.lang3 - org.bukkit.craftbukkit.libs.org.apache.commons.lang3 - - - org.apache.http - org.bukkit.craftbukkit.libs.org.apache.http - - - org.apache.maven - org.bukkit.craftbukkit.libs.org.apache.maven - - - org.codehaus.plexus - org.bukkit.craftbukkit.libs.org.codehaus.plexus - - - org.eclipse.aether - org.bukkit.craftbukkit.libs.org.eclipse.aether - - - org.eclipse.sisu - org.bukkit.craftbukkit.libs.org.eclipse.sisu - - - org.objectweb.asm - org.bukkit.craftbukkit.libs.org.objectweb.asm - - - org.bukkit.craftbukkit - org.bukkit.craftbukkit.v${minecraft_version} - - org.bukkit.craftbukkit.Main* - - - - - - META-INF/services/java.sql.Driver - - - - - - - - net.md-5 - specialsource-maven-plugin - 1.2.2 - - - package - - remap - - remap-fields - - org.spigotmc:minecraft-server:${project.version}:csrg:maps-spigot-fields - true - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - eclipse - - - - org.codehaus.plexus - plexus-compiler-eclipse - 2.8.8 - - - org.eclipse.jdt - ecj - 3.26.0 - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - ${basedir}/target/test-server - - org/bukkit/craftbukkit/inventory/ItemStack*Test.java - - - - - - - - - shadeSourcesJar - - true - true - - - - development - - false - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.1.2 - - - process-classes - - check - - - - - checkstyle.xml - true - - - - com.puppycrawl.tools - checkstyle - 8.44 - - - - - org.codehaus.mojo - animal-sniffer-maven-plugin - 1.20 - - - process-classes - - check - - - - - - org.codehaus.mojo.signature - java18 - 1.0 - - - - - - - - remapped - - - - net.md-5 - specialsource-maven-plugin - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${project.version}:csrg:maps-spigot - true - true - remapped-obf - - - - package - - remap - - remap-mojang - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${project.version}:txt:maps-mojang - true - remapped-mojang - - - - - - - - -