11import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
22import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
4- // TODO: document this file
5-
64plugins {
75 kotlin(" jvm" ) version " 1.7.0"
86 id(" fabric-loom" ) version " 0.12-SNAPSHOT"
@@ -18,7 +16,6 @@ version = "$modVersion+$minecraftVersion"
1816val mavenGroup: String by project
1917group = mavenGroup
2018
21- val loaderVersion: String by project
2219val fabricVersion: String by project
2320
2421val requiredDependencyMods = dependencyModsOfType(" required" )
@@ -45,26 +42,29 @@ repositories {
4542
4643val shade: Configuration by configurations.creating {
4744 isCanBeResolved = true
45+ // Exclude slf4j because it is already provided by Minecraft
4846 exclude(group = " org.slf4j" )
4947}
5048
5149dependencies {
5250 minecraft(" com.mojang:minecraft:$minecraftVersion " )
5351 mappings(loom.officialMojangMappings())
5452
55- modImplementation(" net.fabricmc:fabric-loader:$loaderVersion " )
53+ val loaderDevVersion: String by project
54+ modImplementation(" net.fabricmc:fabric-loader:$loaderDevVersion " )
5655 modImplementation(" net.fabricmc.fabric-api:fabric-api:$fabricVersion " )
5756
5857 shadeApi(kotlin(" stdlib" , " 1.7.0" ))
5958 shadeApi(" org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4" )
6059
60+ // Declare mod dependencies listed in gradle.properties
6161 for (mod in requiredDependencyMods) includeModImpl(" ${mod.artifact} :${mod.version} " )
6262 for (mod in optionalDependencyMods) modCompileOnly(" ${mod.artifact} :${mod.version} " )
6363
64- // discord rpc
64+ // Discord RPC TODO: remove
6565 shadeImpl(" com.jagrosh:DiscordIPC:0.4" )
6666
67- // websocket TODO: clean this up
67+ // Websocket TODO: clean this up
6868 shadeImpl(" org.java-websocket:Java-WebSocket:1.5.3" )
6969 includeImpl(" javax.websocket:javax.websocket-api:1.1" )
7070}
@@ -86,22 +86,26 @@ tasks {
8686 withType<KotlinCompile > {
8787 kotlinOptions {
8888 jvmTarget = " 17"
89+ // Compile Kotlin interfaces with Java 8 default methods
8990 freeCompilerArgs = listOf (" -Xjvm-default=all" )
9091 }
9192 }
9293
9394 processResources {
95+ val loaderModVersion: String by project
96+ // These properties can be used in fabric_mod_json_template.txt in Groovy template syntax
9497 val exposedProperties = arrayOf(
9598 " modName" to modName,
9699 " version" to version,
97100 " minecraftVersion" to minecraftVersion,
98- " loaderVersion" to loaderVersion ,
101+ " loaderVersion" to loaderModVersion ,
99102 " fabricVersion" to fabricVersion
100103 )
101104
102105 inputs.properties(* exposedProperties)
103106 inputs.properties(project.properties.filterKeys { it.startsWith(" required." ) })
104107
108+ // Evaluate fabric_mod_json_template.txt as a Groovy template
105109 filesMatching(" fabric_mod_json_template.txt" ) {
106110 val metadataRegex = Regex (""" \+[\d\.]+$""" )
107111 expand(
@@ -122,19 +126,22 @@ tasks {
122126
123127 val relocate by registering(ConfigureShadowRelocation ::class ) {
124128 target = shadowJar.get()
129+ // Repackage shaded dependencies
125130 prefix = " $mavenGroup .recode.shaded"
126131 }
127132
128133 shadowJar {
129134 dependsOn(relocate)
130135 configurations = listOf (shade)
136+ // Output shaded jar in the correct destination to be used by remapJar
131137 destinationDirectory.set(file(" build/devlibs" ))
132138 archiveClassifier.set(" dev" )
133139
134140 from(" LICENSE" )
135141 }
136142
137143 remapJar {
144+ // Use the shaded jar with remapJar, since jar is disabled
138145 inputFile.value(shadowJar.get().archiveFile)
139146 }
140147}
@@ -183,6 +190,9 @@ data class DependencyMod(
183190 val versionKey get() = " "
184191}
185192
193+ /* *
194+ * @return The list of [DependencyMod] values matching [type] in gradle.properties.
195+ */
186196fun dependencyModsOfType (type : String ) = properties.mapNotNull { (key, value) ->
187197 Regex (""" $type \.([a-z][a-z0-9-_]{1,63})\.artifact""" ).matchEntire(key)?.let { match ->
188198 val id = match.groupValues[1 ]
0 commit comments