|
15 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | */ |
17 | 17 |
|
| 18 | +import org.apache.tools.ant.taskdefs.condition.Os |
18 | 19 | import org.gradle.internal.jvm.* |
19 | | -import net.fabricmc.loom.api.LoomGradleExtensionAPI |
| 20 | +import org.gradle.kotlin.dsl.dependencies |
| 21 | +import org.gradle.kotlin.dsl.provideDelegate |
| 22 | +import org.gradle.kotlin.dsl.register |
20 | 23 | import java.util.* |
21 | 24 |
|
22 | | -val modId: String by project |
23 | | -val modVersion: String by project |
24 | | -val mavenGroup: String by project |
25 | | -val minecraftVersion: String by project |
26 | | -val yarnMappings: String by project |
| 25 | +val modId : String by project |
| 26 | +val mavenGroup : String by project |
| 27 | +val modVersion : String by project |
| 28 | +val minecraftVersion : String by project |
| 29 | +val yarnMappings : String by project |
| 30 | +val fabricLoaderVersion : String by project |
| 31 | +val fabricApiVersion : String by project |
| 32 | +val kotlinFabricVersion : String by project |
| 33 | +val pngEncoderVersion : String by project |
| 34 | +val discordIPCVersion : String by project |
| 35 | +val classGraphVersion : String by project |
| 36 | +val kotlinVersion : String by project |
| 37 | +val ktorVersion : String by project |
| 38 | +val mockitoKotlin : String by project |
| 39 | +val mockitoInline : String by project |
| 40 | +val mockkVersion : String by project |
| 41 | +val spairVersion : String by project |
| 42 | + |
27 | 43 |
|
28 | 44 | val libs = file("libs") |
29 | | -val targets = listOf("META-INF/*.toml", "fabric.mod.json") |
| 45 | +val targets = listOf("fabric.mod.json") |
30 | 46 | val replacements = file("gradle.properties").inputStream().use { stream -> |
31 | 47 | Properties().apply { load(stream) } |
32 | 48 | }.map { (k, v) -> k.toString() to v.toString() }.toMap() |
33 | 49 |
|
34 | | -val Project.loom: LoomGradleExtensionAPI |
35 | | - get() = (this as ExtensionAware).extensions.getByName("loom") as LoomGradleExtensionAPI |
36 | | - |
37 | 50 | plugins { |
38 | | - kotlin("jvm") version "2.1.10" |
| 51 | + kotlin("jvm") version "2.2.0" |
39 | 52 | id("org.jetbrains.dokka") version "2.0.0" |
40 | | - id("architectury-plugin") version "3.4-SNAPSHOT" |
41 | | - id("dev.architectury.loom") version "1.10-SNAPSHOT" apply false |
42 | | - id("com.gradleup.shadow") version "9.0.0-beta13" apply false |
| 53 | + id("fabric-loom") version "1.10-SNAPSHOT" |
| 54 | + id("com.gradleup.shadow") version "9.0.0-rc1" |
43 | 55 | id("maven-publish") |
44 | 56 | } |
45 | 57 |
|
46 | | -architectury { |
47 | | - minecraft = minecraftVersion |
48 | | -} |
49 | | - |
50 | | -subprojects { |
51 | | - apply(plugin = "dev.architectury.loom") |
52 | | - apply(plugin = "org.jetbrains.dokka") |
53 | | - apply(plugin = "maven-publish") |
| 58 | +group = mavenGroup |
| 59 | +version = modVersion |
54 | 60 |
|
55 | | - dependencies { |
56 | | - "minecraft"("com.mojang:minecraft:$minecraftVersion") |
57 | | - "mappings"("net.fabricmc:yarn:$minecraftVersion+$yarnMappings:v2") |
58 | | - } |
59 | | - |
60 | | - publishing { |
61 | | - publications { |
62 | | - register<MavenPublication>("maven") { |
63 | | - groupId = mavenGroup |
64 | | - artifactId = if (project.name == "common") modId else "$modId-${project.name}" |
65 | | - version = "$modVersion+$minecraftVersion" |
| 61 | +base.archivesName = modId |
66 | 62 |
|
67 | | - from(components["java"]) |
68 | | - } |
69 | | - } |
| 63 | +repositories { |
| 64 | + mavenLocal() // Allow the use of local repositories |
| 65 | + maven("https://maven.shedaniel.me/") // Architectury |
| 66 | + maven("https://maven.terraformersmc.com/releases/") |
| 67 | + maven("https://maven.2b2t.vc/releases") // Baritone |
| 68 | + maven("https://jitpack.io") // KDiscordIPC |
| 69 | + maven("https://raw.githubusercontent.com/kotlin-graphics/mary/master") |
| 70 | + mavenCentral() |
70 | 71 |
|
71 | | - repositories { |
72 | | - maven { |
73 | | - name = "reposilite" |
74 | | - url = uri("https://maven.lambda-client.org/lambda") |
75 | | - credentials(PasswordCredentials::class) |
76 | | - authentication { |
77 | | - create<BasicAuthentication>("basic") |
78 | | - } |
79 | | - } |
80 | | - } |
| 72 | + // Allow the use of local libraries |
| 73 | + flatDir { |
| 74 | + dirs(libs) |
81 | 75 | } |
| 76 | +} |
82 | 77 |
|
83 | | - if (path == ":common") return@subprojects |
| 78 | +loom { |
| 79 | + accessWidenerPath = file("src/main/resources/$modId.accesswidener") |
84 | 80 |
|
85 | | - loom.mods { |
86 | | - maybeCreate("main").apply { |
87 | | - sourceSet(project.sourceSets.main.get()) |
88 | | - sourceSet(project(":common").sourceSets.main.get()) |
89 | | - } |
90 | | - } |
| 81 | + // Apply access wideners transitively (other mods) |
| 82 | + enableTransitiveAccessWideners = true |
91 | 83 |
|
92 | | - loom.runs { |
| 84 | + runs { |
93 | 85 | all { |
94 | 86 | property("lambda.dev", "youtu.be/RYnFIRc0k6E") |
| 87 | + |
95 | 88 | property("org.lwjgl.util.Debug", "true") |
| 89 | + property("org.lwjgl.util.DebugLoader", "true") |
| 90 | + //property("org.lwjgl.util.DebugAllocator", "true") |
| 91 | + //property("org.lwjgl.util.DebugAllocator.fast", "true") |
| 92 | + property("org.lwjgl.util.DebugStack", "true") |
| 93 | + property("org.lwjgl.util.DebugFunctions", "true") |
96 | 94 |
|
97 | 95 | vmArgs("-XX:+HeapDumpOnOutOfMemoryError", "-XX:+CreateCoredumpOnCrash", "-XX:+UseOSErrorReporting") |
98 | 96 | programArgs("--username", "Steve", "--uuid", "8667ba71b85a4004af54457a9734eed7", "--accessToken", "****", "--userType", "msa") |
99 | 97 | } |
100 | 98 | } |
| 99 | +} |
101 | 100 |
|
102 | | - tasks { |
103 | | - processResources { |
104 | | - // Replaces placeholders in the mod info files |
105 | | - filesMatching(targets) { expand(replacements) } |
| 101 | +val includeLib: Configuration by configurations.creating |
| 102 | +val includeMod: Configuration by configurations.creating |
| 103 | +val shadowLib: Configuration by configurations.creating { isCanBeConsumed = false } |
| 104 | +val shadowMod: Configuration by configurations.creating { isCanBeConsumed = false } |
106 | 105 |
|
107 | | - // Forces the task to always run |
108 | | - outputs.upToDateWhen { false } |
109 | | - } |
| 106 | +fun DependencyHandlerScope.setupConfigurations() { |
| 107 | + includeLib.dependencies.forEach { |
| 108 | + implementation(it) |
| 109 | + include(it) |
| 110 | + } |
110 | 111 |
|
111 | | - register<Exec>("renderDoc") { |
112 | | - val javaHome = Jvm.current().javaHome |
113 | | - val gradleWrapper = rootProject.tasks.wrapper.get().jarFile.absolutePath |
114 | | - |
115 | | - commandLine = listOf( |
116 | | - "renderdoccmd", "capture", "--opt-api-validation", "--opt-api-validation-unmute", "--opt-hook-children", |
117 | | - "--wait-for-exit", "--working-dir", ".", "$javaHome/bin/java", "-Xmx64m", "-Xms64m", |
118 | | - /*"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005",*/ |
119 | | - "-Dorg.gradle.appname=gradlew", "-Dorg.gradle.java.home=$javaHome", "-classpath", gradleWrapper, "org.gradle.wrapper.GradleWrapperMain", |
120 | | - "${this@subprojects.path}:runClient", |
121 | | - ) |
122 | | - } |
| 112 | + includeMod.dependencies.forEach { |
| 113 | + modImplementation(it) |
| 114 | + include(it) |
| 115 | + } |
| 116 | + |
| 117 | + shadowLib.dependencies.forEach { |
| 118 | + implementation(it) |
| 119 | + } |
| 120 | + |
| 121 | + shadowMod.dependencies.forEach { |
| 122 | + modImplementation(it) |
123 | 123 | } |
124 | 124 | } |
125 | 125 |
|
126 | | -allprojects { |
127 | | - apply(plugin = "java") |
128 | | - apply(plugin = "architectury-plugin") |
129 | | - apply(plugin = "maven-publish") |
130 | | - apply(plugin = "org.jetbrains.kotlin.jvm") |
| 126 | +dependencies { |
| 127 | + // Read this if you'd like to understand the gradle dependency hell |
| 128 | + // https://medium.com/@nagendra.raja/understanding-configurations-and-dependencies-in-gradle-ad0827619501 |
| 129 | + |
| 130 | + minecraft("com.mojang:minecraft:$minecraftVersion") |
| 131 | + mappings("net.fabricmc:yarn:$minecraftVersion+$yarnMappings:v2") |
| 132 | + |
| 133 | + // Fabric |
| 134 | + modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion") |
| 135 | + modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion+$minecraftVersion") |
| 136 | + modImplementation("net.fabricmc:fabric-language-kotlin:$kotlinFabricVersion.$kotlinVersion") |
| 137 | + |
| 138 | + // Add dependencies on the required Kotlin modules. |
| 139 | + includeLib("io.github.classgraph:classgraph:${classGraphVersion}") |
| 140 | + includeLib("com.github.Edouard127:KDiscordIPC:$discordIPCVersion") |
| 141 | + includeLib("com.pngencoder:pngencoder:$pngEncoderVersion") |
| 142 | + |
| 143 | + includeLib("io.github.spair:imgui-java-binding:$spairVersion") |
| 144 | + includeLib("io.github.spair:imgui-java-lwjgl3:$spairVersion") |
| 145 | + runtimeOnly("io.github.spair:imgui-java-natives-windows:$spairVersion") |
| 146 | + runtimeOnly("io.github.spair:imgui-java-natives-linux:$spairVersion") |
| 147 | + runtimeOnly("io.github.spair:imgui-java-natives-macos:$spairVersion") |
| 148 | + |
| 149 | + // Ktor |
| 150 | + includeLib("io.ktor:ktor-client-core:$ktorVersion") |
| 151 | + shadowLib("io.ktor:ktor-client-cio:$ktorVersion") { exclude(group = "org.jetbrains.kotlin"); exclude(group = "org.jetbrains.kotlinx"); exclude(group = "org.slf4j") } |
| 152 | + includeLib("io.ktor:ktor-client-content-negotiation:$ktorVersion") |
| 153 | + includeLib("io.ktor:ktor-serialization-gson:$ktorVersion") |
| 154 | + |
| 155 | + // Add mods to the mod jar |
| 156 | + includeMod("com.github.rfresh2:baritone-fabric:$minecraftVersion") |
| 157 | + |
| 158 | + // Test implementations |
| 159 | + testImplementation(kotlin("test")) |
| 160 | + testImplementation("org.mockito.kotlin:mockito-kotlin:$mockitoKotlin") |
| 161 | + testImplementation("org.mockito:mockito-inline:$mockitoInline") |
| 162 | + testImplementation("io.mockk:mockk:${mockkVersion}") |
| 163 | + |
| 164 | + // Finish the configuration |
| 165 | + setupConfigurations() |
| 166 | +} |
131 | 167 |
|
132 | | - group = mavenGroup |
133 | | - version = modVersion |
| 168 | +tasks { |
| 169 | + test { |
| 170 | + useJUnitPlatform() |
| 171 | + jvmArgs("-XX:+EnableDynamicAgentLoading", "-Xshare:off") |
| 172 | + } |
134 | 173 |
|
135 | | - base.archivesName = modId |
| 174 | + shadowJar { |
| 175 | + archiveClassifier = "dev-shadow" |
| 176 | + archiveVersion = "$modVersion+$minecraftVersion" |
| 177 | + configurations = listOf(shadowLib, shadowMod) |
| 178 | + } |
136 | 179 |
|
137 | | - repositories { |
138 | | - mavenLocal() // Allow the use of local repositories |
139 | | - maven("https://maven.shedaniel.me/") // Architectury |
140 | | - maven("https://maven.terraformersmc.com/releases/") |
141 | | - maven("https://maven.2b2t.vc/releases") // Baritone |
142 | | - maven("https://jitpack.io") // KDiscordIPC |
143 | | - mavenCentral() |
| 180 | + remapJar { |
| 181 | + dependsOn(shadowJar) |
144 | 182 |
|
145 | | - // Allow the use of local libraries |
146 | | - flatDir { |
147 | | - dirs(libs) |
148 | | - } |
| 183 | + inputFile = shadowJar.get().archiveFile |
| 184 | + archiveVersion = "$modVersion+$minecraftVersion" |
149 | 185 | } |
150 | 186 |
|
151 | | - java { |
152 | | - withSourcesJar() |
| 187 | + processResources { |
| 188 | + filesMatching(targets) { expand(replacements) } |
153 | 189 |
|
154 | | - sourceCompatibility = JavaVersion.VERSION_21 |
155 | | - targetCompatibility = JavaVersion.VERSION_21 |
| 190 | + // Forces the task to always run |
| 191 | + outputs.upToDateWhen { false } |
156 | 192 | } |
| 193 | + |
| 194 | + register<Exec>("renderDoc") { |
| 195 | + // You need renderdoc installed on your system and available in your environment variables in order |
| 196 | + // to use this task. |
| 197 | + // You can download it from their official website at https://renderdoc.org/ |
| 198 | + |
| 199 | + val javaHome = Jvm.current().javaHome |
| 200 | + val gradle = rootProject.tasks.wrapper.get().jarFile.absolutePath |
| 201 | + |
| 202 | + val seperator = |
| 203 | + if (Os.isFamily(Os.FAMILY_WINDOWS)) ";" else ":" |
| 204 | + |
| 205 | + commandLine = listOf( |
| 206 | + "renderdoccmd", "capture", "--opt-api-validation", "--opt-api-validation-unmute", "--opt-hook-children", "--wait-for-exit", "--working-dir", ".", |
| 207 | + "$javaHome/bin/java", |
| 208 | + //"-javaagent:${projectDir.resolve("lwjglx-debug-1.0.0.jar")}=t", |
| 209 | + //"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", |
| 210 | + "-Dorg.gradle.appname=gradlew", |
| 211 | + "-Dorg.gradle.java.home=$javaHome", |
| 212 | + "-Dorg.lwjgl.util.Debug=true", |
| 213 | + "-Dorg.lwjgl.util.DebugLoader=true", |
| 214 | + "-Dorg.lwjgl.util.DebugAllocator=true", |
| 215 | + "-Dorg.lwjgl.util.DebugStack=true", |
| 216 | + "-Dorg.lwjgl.util.DebugFunctions=true", |
| 217 | + "-cp", listOf(projectDir.resolve("lwjgl.jar"), gradle, projectDir.resolve("lwjglx-debug-1.0.0.jar")) |
| 218 | + .joinToString(seperator), |
| 219 | + "org.gradle.wrapper.GradleWrapperMain", |
| 220 | + "runClient", |
| 221 | + ) |
| 222 | + } |
| 223 | +} |
| 224 | + |
| 225 | +kotlin { |
| 226 | + jvmToolchain(21) |
| 227 | +} |
| 228 | + |
| 229 | +java { |
| 230 | + withSourcesJar() |
| 231 | + |
| 232 | + sourceCompatibility = JavaVersion.VERSION_21 |
| 233 | + targetCompatibility = JavaVersion.VERSION_21 |
157 | 234 | } |
0 commit comments