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..9c4382ef7373110b6e72163779316ff40234a992 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,141 @@ +import io.papermc.paperweight.util.* + +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") + runtimeOnly("org.xerial:sqlite-jdbc:3.36.0.3") + runtimeOnly("mysql:mysql-connector-java:8.0.27") + + 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") { + 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_18_R1" + relocate("org.bukkit.craftbukkit" to "org.bukkit.craftbukkit.v$packageVersion") { + exclude("org.bukkit.craftbukkit.Main*") + } +} + +tasks.shadowJar { + configurations = listOf(project.configurations.vanillaServer.get()) + archiveClassifier.set("mojang-mapped") + + for (relocation in relocation.relocations.get()) { + relocate(relocation.fromPackage, relocation.toPackage) { + for (exclude in relocation.excludes) { + exclude(exclude) + } + } + } +} + +tasks.test { + exclude("org/bukkit/craftbukkit/inventory/ItemStack*Test.class") +} + +fun TaskContainer.registerRunTask( + name: String, + block: JavaExec.() -> Unit +): TaskProvider = register(name) { + group = "paper" + mainClass.set("org.bukkit.craftbukkit.Main") + standardInput = System.`in` + workingDir = rootProject.layout.projectDirectory + .dir(providers.gradleProperty("paper.runWorkDir").forUseAtConfigurationTime().getOrElse("run")) + .asFile + javaLauncher.set(project.javaToolchains.defaultJavaLauncher(project)) + + 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 (providers.gradleProperty("paper.runDisableWatchdog").getOrElse("false") == "true") { + systemProperty("disable.watchdog", true) + } + + val memoryGb = providers.gradleProperty("paper.runMemoryGb").forUseAtConfigurationTime().getOrElse("2") + val modifiedJvmArgs = jvmArgs ?: arrayListOf() + modifiedJvmArgs.addAll(listOf("-Xms${memoryGb}G", "-Xmx${memoryGb}G")) + jvmArgs = modifiedJvmArgs + + doFirst { + workingDir.mkdirs() + } + + block(this) +} + +val runtimeClasspathWithoutVanillaServer = configurations.runtimeClasspath.flatMap { it.elements } + .zip(configurations.vanillaServer.map { it.singleFile.absolutePath }) { runtime, vanilla -> + runtime.filterNot { it.asFile.absolutePath == vanilla } + } + +tasks.registerRunTask("runShadow") { + description = "Spin up a test server from the shadowJar archiveFile" + classpath(tasks.shadowJar.flatMap { it.archiveFile }) + classpath(runtimeClasspathWithoutVanillaServer) +} + +tasks.registerRunTask("runReobf") { + description = "Spin up a test server from the reobfJar output jar" + classpath(tasks.reobfJar.flatMap { it.outputJar }) + classpath(runtimeClasspathWithoutVanillaServer) +} + +tasks.registerRunTask("runDev") { + description = "Spin up a non-relocated Mojang-mapped test server" + classpath(sourceSets.main.map { it.runtimeClasspath }) +} diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 56938962e9ba6b188c2f4bc1694b911f05994436..0000000000000000000000000000000000000000 --- a/pom.xml +++ /dev/null @@ -1,540 +0,0 @@ - - 4.0.0 - org.spigotmc - spigot - jar - 1.18.1-R0.1-SNAPSHOT - Spigot - https://www.spigotmc.org/ - - - org.spigotmc - spigot-parent - dev-SNAPSHOT - ../pom.xml - - - - true - UTF-8 - unknown - git - 1_18_R1 - 16 - 16 - - - - - minecraft-libraries - Minecraft Libraries - https://libraries.minecraft.net/ - - - - - - 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.ow2.asm - asm - 9.2 - compile - - - - com.github.oshi - oshi-core - 5.8.2 - compile - - - com.mojang - authlib - 3.2.38 - compile - - - com.mojang - brigadier - 1.0.18 - compile - - - com.mojang - datafixerupper - 4.0.26 - compile - - - com.mojang - javabridge - 1.2.24 - compile - - - commons-io - commons-io - 2.11.0 - compile - - - io.netty - netty-all - 4.1.68.Final - compile - - - it.unimi.dsi - fastutil - 8.5.6 - compile - - - net.sf.jopt-simple - jopt-simple - 5.0.4 - compile - - - org.apache.commons - commons-lang3 - 3.12.0 - compile - - - org.apache.logging.log4j - log4j-core - 2.14.1 - compile - - - org.apache.logging.log4j - log4j-slf4j18-impl - 2.14.1 - compile - - - org.slf4j - slf4j-api - 1.8.0-beta4 - compile - - - - com.googlecode.json-simple - json-simple - 1.1.1 - runtime - - - org.xerial - sqlite-jdbc - 3.36.0.3 - runtime - - - mysql - mysql-connector-java - 8.0.27 - 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 - - - - - org.bukkit.craftbukkit - org.bukkit.craftbukkit.v${minecraft_version} - - org.bukkit.craftbukkit.bootstrap.* - org.bukkit.craftbukkit.Main* - - - - - - - - - net.md-5 - specialsource-maven-plugin - 1.2.3 - - - package - - remap - - remap-members - - ${project.build.directory}/server.txt - org.spigotmc:minecraft-server:${project.version}:csrg:maps-spigot-members - true - - - - - - net.nicoulaj.maven.plugins - checksum-maven-plugin - 1.11 - - - package - - artifacts - dependencies - - - - SHA-256 - - true - - compile - runtime - - true - true - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.3.0 - - - package - - single - - - - - false - - - org.bukkit.craftbukkit.bootstrap.Main - - - false - - ${project.basedir}/src/assembly/bootstrap.xml - - - - - - - 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.27.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 - - - test-compile - - check - - - - - checkstyle.xml - true - - - - com.puppycrawl.tools - checkstyle - 8.45.1 - - - - - org.codehaus.mojo - animal-sniffer-maven-plugin - 1.20 - - - process-classes - - - - - - - - org.codehaus.mojo.signature - java18 - 1.0 - - - - - - - - remapped - - - - net.md-5 - specialsource-maven-plugin - - - verify - - remap - - remap-obf - - org.spigotmc:minecraft-server:${project.version}:csrg:maps-spigot - true - true - remapped-obf - - - - verify - - 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 - - - - - - - - -