Paper/patches/server/0001-Setup-Gradle-project.patch

724 lines
29 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kyle Wood <kyle@denwav.dev>
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..75c858870a55f7282a0e3500f803cb330b462f37
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,137 @@
+import io.papermc.paperweight.util.*
+
+plugins {
+ java
+ `maven-publish`
+ id("com.github.johnrengelman.shadow")
+}
+
+dependencies {
+ implementation(project(":paper-api"))
+ implementation("jline:jline:2.12.1")
+ implementation("org.apache.logging.log4j:log4j-iostreams:2.17.0") {
+ 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.4")
+ runtimeOnly("org.apache.maven.resolver:maven-resolver-connector-basic:1.7.2")
+ runtimeOnly("org.apache.maven.resolver:maven-resolver-transport-http:1.7.2")
+
+ testImplementation("junit:junit:4.13.2")
+ testImplementation("org.hamcrest:hamcrest-library:1.3")
+}
+
+val craftbukkitPackageVersion = "1_18_R2" // Paper
+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<MavenPublication>("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
+ relocate("org.bukkit.craftbukkit" to "org.bukkit.craftbukkit.v$craftbukkitPackageVersion") {
+ 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<JavaExec> = register<JavaExec>(name) {
+ group = "paper"
+ mainClass.set("org.bukkit.craftbukkit.Main")
+ standardInput = System.`in`
+ workingDir = rootProject.layout.projectDirectory
+ .dir(providers.gradleProperty("paper.runWorkDir").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").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 ac2dbe041d8a286ed7a34bf20c88464693f32a25..0000000000000000000000000000000000000000
--- a/pom.xml
+++ /dev/null
@@ -1,546 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.spigotmc</groupId>
- <artifactId>spigot</artifactId>
- <packaging>jar</packaging>
- <version>1.18.2-R0.1-SNAPSHOT</version>
- <name>Spigot</name>
- <url>https://www.spigotmc.org/</url>
-
- <parent>
- <groupId>org.spigotmc</groupId>
- <artifactId>spigot-parent</artifactId>
- <version>dev-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <properties>
- <skipTests>true</skipTests>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <api.version>unknown</api.version>
- <bt.name>git</bt.name>
- <minecraft_version>1_18_R2</minecraft_version>
- <maven.compiler.source>16</maven.compiler.source>
- <maven.compiler.target>16</maven.compiler.target>
- </properties>
-
- <repositories>
- <repository>
- <id>minecraft-libraries</id>
- <name>Minecraft Libraries</name>
- <url>https://libraries.minecraft.net/</url>
- </repository>
- </repositories>
-
- <dependencies>
- <dependency>
- <groupId>org.spigotmc</groupId>
- <artifactId>spigot-api</artifactId>
- <version>${project.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.spigotmc</groupId>
- <artifactId>minecraft-server</artifactId>
- <version>${project.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
- <version>2.12.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-iostreams</artifactId>
- <version>2.17.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.ow2.asm</groupId>
- <artifactId>asm</artifactId>
- <version>9.2</version>
- <scope>compile</scope>
- </dependency>
- <!-- Mojang depends -->
- <dependency>
- <groupId>com.github.oshi</groupId>
- <artifactId>oshi-core</artifactId>
- <version>5.8.5</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>com.mojang</groupId>
- <artifactId>authlib</artifactId>
- <version>3.3.39</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>com.mojang</groupId>
- <artifactId>brigadier</artifactId>
- <version>1.0.18</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>com.mojang</groupId>
- <artifactId>datafixerupper</artifactId>
- <version>4.1.27</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>com.mojang</groupId>
- <artifactId>javabridge</artifactId>
- <version>1.2.24</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>com.mojang</groupId>
- <artifactId>logging</artifactId>
- <version>1.0.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.11.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-all</artifactId>
- <version>4.1.68.Final</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>it.unimi.dsi</groupId>
- <artifactId>fastutil</artifactId>
- <version>8.5.6</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>net.sf.jopt-simple</groupId>
- <artifactId>jopt-simple</artifactId>
- <version>5.0.4</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.12.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <version>2.17.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j18-impl</artifactId>
- <version>2.17.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.8.0-beta4</version>
- <scope>compile</scope>
- </dependency>
- <!-- deprecated API depend -->
- <dependency>
- <groupId>com.googlecode.json-simple</groupId>
- <artifactId>json-simple</artifactId>
- <version>1.1.1</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.xerial</groupId>
- <artifactId>sqlite-jdbc</artifactId>
- <version>3.36.0.3</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>8.0.27</version>
- <scope>runtime</scope>
- </dependency>
- <!-- add these back in as they are not exposed by the API -->
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-resolver-provider</artifactId>
- <version>3.8.4</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.resolver</groupId>
- <artifactId>maven-resolver-connector-basic</artifactId>
- <version>1.7.2</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.resolver</groupId>
- <artifactId>maven-resolver-transport-http</artifactId>
- <version>1.7.2</version>
- <scope>runtime</scope>
- </dependency>
- <!-- testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- <version>1.3</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <!-- This builds a completely 'ready to start' jar with all dependencies inside -->
- <build>
- <plugins>
- <plugin>
- <groupId>net.md-5</groupId>
- <artifactId>scriptus</artifactId>
- <version>0.4.1</version>
- <executions>
- <execution>
- <id>ex-spigot</id>
- <configuration>
- <format>${bt.name}-Spigot-%s</format>
- <scmDirectory>../</scmDirectory>
- <descriptionProperty>spigot.desc</descriptionProperty>
- </configuration>
- <phase>initialize</phase>
- <goals>
- <goal>describe</goal>
- </goals>
- </execution>
- <execution>
- <id>ex-craftbukkit</id>
- <configuration>
- <format>-%s</format>
- <scmDirectory>../../CraftBukkit</scmDirectory>
- <descriptionProperty>craftbukkit.desc</descriptionProperty>
- </configuration>
- <phase>initialize</phase>
- <goals>
- <goal>describe</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-clean-plugin</artifactId>
- <version>3.1.0</version>
- <executions>
- <execution>
- <phase>initialize</phase>
- <goals>
- <goal>clean</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>3.2.0</version>
- <configuration>
- <archive>
- <manifest>
- <addDefaultEntries>false</addDefaultEntries>
- </manifest>
- <manifestEntries>
- <Main-Class>org.bukkit.craftbukkit.Main</Main-Class>
- <Implementation-Title>CraftBukkit</Implementation-Title>
- <Implementation-Version>${spigot.desc}${craftbukkit.desc}</Implementation-Version>
- <Implementation-Vendor>${project.build.outputTimestamp}</Implementation-Vendor>
- <Specification-Title>Bukkit</Specification-Title>
- <Specification-Version>${api.version}</Specification-Version>
- <Specification-Vendor>Bukkit Team</Specification-Vendor>
- <Multi-Release>true</Multi-Release>
- </manifestEntries>
- <manifestSections>
- <manifestSection>
- <name>net/bukkit/</name>
- <manifestEntries>
- <Sealed>true</Sealed>
- </manifestEntries>
- </manifestSection>
- <manifestSection>
- <name>com/bukkit/</name>
- <manifestEntries>
- <Sealed>true</Sealed>
- </manifestEntries>
- </manifestSection>
- <manifestSection>
- <name>org/bukkit/</name>
- <manifestEntries>
- <Sealed>true</Sealed>
- </manifestEntries>
- </manifestSection>
- </manifestSections>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>3.2.4</version>
- <dependencies>
- <dependency>
- <groupId>org.ow2.asm</groupId>
- <artifactId>asm</artifactId>
- <version>9.2</version>
- </dependency>
- <dependency>
- <groupId>org.ow2.asm</groupId>
- <artifactId>asm-commons</artifactId>
- <version>9.2</version>
- </dependency>
- </dependencies>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <createSourcesJar>${shadeSourcesJar}</createSourcesJar>
- <artifactSet>
- <includes>
- <include>org.spigotmc:minecraft-server</include>
- </includes>
- </artifactSet>
- <relocations>
- <relocation>
- <pattern>org.bukkit.craftbukkit</pattern>
- <shadedPattern>org.bukkit.craftbukkit.v${minecraft_version}</shadedPattern>
- <excludes>
- <exclude>org.bukkit.craftbukkit.bootstrap.*</exclude>
- <exclude>org.bukkit.craftbukkit.Main*</exclude>
- </excludes>
- </relocation>
- </relocations>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>net.md-5</groupId>
- <artifactId>specialsource-maven-plugin</artifactId>
- <version>1.2.3</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>remap</goal>
- </goals>
- <id>remap-members</id>
- <configuration>
- <logFile>${project.build.directory}/server.txt</logFile>
- <srgIn>org.spigotmc:minecraft-server:${project.version}:csrg:maps-spigot-members</srgIn>
- <reverse>true</reverse>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>net.nicoulaj.maven.plugins</groupId>
- <artifactId>checksum-maven-plugin</artifactId>
- <version>1.11</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>artifacts</goal>
- <goal>dependencies</goal>
- </goals>
- <configuration>
- <algorithms>
- <algorithm>SHA-256</algorithm>
- </algorithms>
- <quiet>true</quiet>
- <scopes>
- <scope>compile</scope>
- <scope>runtime</scope>
- </scopes>
- <shasumSummary>true</shasumSummary>
- <transitive>true</transitive>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>3.3.0</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- <configuration>
- <archive>
- <manifest>
- <addDefaultEntries>false</addDefaultEntries>
- </manifest>
- <manifestEntries>
- <Main-Class>org.bukkit.craftbukkit.bootstrap.Main</Main-Class>
- </manifestEntries>
- </archive>
- <attach>false</attach>
- <descriptors>
- <descriptor>${project.basedir}/src/assembly/bootstrap.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.8.1</version>
- <configuration>
- <!-- we use the Eclipse compiler as it doesn't need a JDK -->
- <compilerId>eclipse</compilerId>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-compiler-eclipse</artifactId>
- <version>2.8.8</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jdt</groupId>
- <artifactId>ecj</artifactId>
- <version>3.28.0</version>
- </dependency>
- </dependencies>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.12.4</version>
- <configuration>
- <workingDirectory>${basedir}/target/test-server</workingDirectory>
- <excludes>
- <exclude>org/bukkit/craftbukkit/inventory/ItemStack*Test.java</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <profiles>
- <profile>
- <id>shadeSourcesJar</id>
- <properties>
- <shadeSourcesJar>true</shadeSourcesJar>
- <shadeSourcesContent>true</shadeSourcesContent>
- </properties>
- </profile>
- <profile>
- <id>development</id>
- <properties>
- <skipTests>false</skipTests>
- </properties>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <version>3.1.2</version>
- <executions>
- <execution>
- <phase>test-compile</phase>
- <goals>
- <goal>check</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <configLocation>checkstyle.xml</configLocation>
- <includeTestSourceDirectory>true</includeTestSourceDirectory>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>com.puppycrawl.tools</groupId>
- <artifactId>checkstyle</artifactId>
- <version>8.45.1</version>
- </dependency>
- </dependencies>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>animal-sniffer-maven-plugin</artifactId>
- <version>1.20</version>
- <executions>
- <execution>
- <phase>process-classes</phase>
- <goals>
- <!--<goal>check</goal>-->
- </goals>
- </execution>
- </executions>
- <configuration>
- <signature>
- <groupId>org.codehaus.mojo.signature</groupId>
- <artifactId>java18</artifactId>
- <version>1.0</version>
- </signature>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- <profile>
- <id>remapped</id>
- <build>
- <plugins>
- <plugin>
- <groupId>net.md-5</groupId>
- <artifactId>specialsource-maven-plugin</artifactId>
- <executions>
- <execution>
- <phase>verify</phase>
- <goals>
- <goal>remap</goal>
- </goals>
- <id>remap-obf</id>
- <configuration>
- <srgIn>org.spigotmc:minecraft-server:${project.version}:csrg:maps-spigot</srgIn>
- <reverse>true</reverse>
- <remappedArtifactAttached>true</remappedArtifactAttached>
- <remappedClassifierName>remapped-obf</remappedClassifierName>
- </configuration>
- </execution>
- <execution>
- <phase>verify</phase>
- <goals>
- <goal>remap</goal>
- </goals>
- <id>remap-mojang</id>
- <configuration>
- <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
- <srgIn>org.spigotmc:minecraft-server:${project.version}:txt:maps-mojang</srgIn>
- <remappedArtifactAttached>true</remappedArtifactAttached>
- <remappedClassifierName>remapped-mojang</remappedClassifierName>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-</project>