Skip to content

Commit c912d92

Browse files
committed
Refactor: Build scripts
1 parent 11a6c5a commit c912d92

File tree

4 files changed

+60
-57
lines changed

4 files changed

+60
-57
lines changed

build.gradle.kts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
21
import net.fabricmc.loom.api.LoomGradleExtensionAPI
3-
import net.fabricmc.loom.task.RemapJarTask
42
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
53
import java.util.*
64

7-
val targets = listOf("META-INF/*.toml", "fabric.mod.json")
8-
val replacements = file("gradle.properties").inputStream().use { stream ->
9-
Properties().apply { load(stream) }
10-
}.map { (k, v) -> k.toString() to v.toString() }.toMap()
11-
125
val modId: String by project
136
val modVersion: String by project
147
val mavenGroup: String by project
158
val minecraftVersion: String by project
169
val yarnMappings: String by project
1710

1811
val libs = file("libs")
12+
val targets = listOf("META-INF/*.toml", "fabric.mod.json")
13+
val replacements = file("gradle.properties").inputStream().use { stream ->
14+
Properties().apply { load(stream) }
15+
}.map { (k, v) -> k.toString() to v.toString() }.toMap()
16+
1917
val Project.loom: LoomGradleExtensionAPI
2018
get() = (this as ExtensionAware).extensions.getByName("loom") as LoomGradleExtensionAPI
2119

2220
plugins {
2321
kotlin("jvm") version "2.0.0"
2422
id("org.jetbrains.dokka") version "1.9.20"
2523
id("architectury-plugin") version "3.4-SNAPSHOT"
26-
id("dev.architectury.loom") version "1.6-SNAPSHOT" apply false
24+
id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false
2725
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
2826
}
2927

@@ -42,33 +40,7 @@ subprojects {
4240

4341
if (path == ":common") return@subprojects
4442

45-
apply(plugin = "com.github.johnrengelman.shadow")
46-
47-
val versionWithMCVersion = "$modVersion+$minecraftVersion"
48-
4943
tasks {
50-
val shadowCommon by configurations.creating {
51-
isCanBeConsumed = false
52-
isCanBeResolved = true
53-
}
54-
55-
val shadow = named<ShadowJar>("shadowJar") {
56-
archiveVersion = versionWithMCVersion
57-
archiveClassifier.set("shadow")
58-
configurations = listOf(shadowCommon)
59-
}
60-
61-
named<RemapJarTask>("remapJar") {
62-
dependsOn(shadow)
63-
inputFile = shadow.flatMap { it.archiveFile }
64-
archiveVersion = versionWithMCVersion
65-
archiveClassifier = ""
66-
}
67-
68-
jar {
69-
enabled = false
70-
}
71-
7244
processResources {
7345
// Replaces placeholders in the mod info files
7446
filesMatching(targets) {

fabric/build.gradle.kts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
val modVersion: String by project
12
val minecraftVersion: String by project
23
val fabricLoaderVersion: String by project
34
val fabricApiVersion: String by project
45
val kotlinFabricVersion: String by project
56

67
base.archivesName = "${base.archivesName.get()}-fabric"
78

9+
plugins {
10+
id("com.github.johnrengelman.shadow") version "8.1.1"
11+
}
12+
813
architectury {
914
platformSetupLoomIde()
1015
fabric()
@@ -40,11 +45,6 @@ fun DependencyHandlerScope.setupConfigurations() {
4045
modImplementation(it)
4146
include(it)
4247
}
43-
44-
shadowBundle.dependencies.forEach {
45-
shadowCommon(it)
46-
shadow(it)
47-
}
4848
}
4949

5050
dependencies {
@@ -73,10 +73,19 @@ dependencies {
7373
}
7474

7575
tasks {
76-
// Access wideners are the successor of the mixins accessor
77-
// that were used in the past to access private fields and methods.
78-
// They allow you to make field, method, and class access public.
76+
shadowJar {
77+
archiveVersion = "$modVersion+$minecraftVersion"
78+
configurations = listOf(shadowBundle)
79+
archiveClassifier = "dev-shadow"
80+
}
81+
7982
remapJar {
83+
dependsOn(shadowJar)
84+
inputFile = shadowJar.get().archiveFile
85+
86+
// Access wideners are the successor of the mixins accessor
87+
// that were used in the past to access private fields and methods.
88+
// They allow you to make field, method, and class access public.
8089
injectAccessWidener = true
8190
}
8291
}

forge/build.gradle.kts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
val modVersion: String by project
12
val minecraftVersion: String by project
23
val forgeVersion: String by project
34
val mixinExtrasVersion: String by project
45
val kotlinForgeVersion: String by project
56

67
base.archivesName = "${base.archivesName.get()}-forge"
78

9+
plugins {
10+
id("com.github.johnrengelman.shadow") version "8.1.1"
11+
}
12+
813
architectury {
914
platformSetupLoomIde()
1015
forge()
@@ -62,11 +67,6 @@ fun DependencyHandlerScope.setupConfigurations() {
6267
forgeRuntimeLibrary(it)
6368
include(it)
6469
}
65-
66-
shadowBundle.dependencies.forEach {
67-
shadowCommon(it)
68-
shadow(it)
69-
}
7070
}
7171

7272
dependencies {
@@ -81,13 +81,13 @@ dependencies {
8181
includeMod("thedarkcolour:kotlinforforge:$kotlinForgeVersion")
8282
includeMod("baritone-api:baritone-unoptimized-forge:1.10.2")
8383

84+
// Fix KFF
85+
compileOnly(kotlin("stdlib"))
86+
8487
// MixinExtras
8588
implementation("io.github.llamalad7:mixinextras-forge:$mixinExtrasVersion")
8689
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!)
8790

88-
// Fix KFF
89-
compileOnly(kotlin("stdlib"))
90-
9191
// Disable reflections logging
9292
include("org.slf4j:slf4j-nop:2.0.13")
9393

@@ -100,9 +100,24 @@ dependencies {
100100
}
101101

102102
tasks {
103+
// Merge the resources and classes into the same directory.
104+
// This is done because java expects modules to be in a single directory.
105+
// And if we have it in multiple we have to do performance intensive hacks like having the UnionFileSystem
106+
// This will eventually be migrated to ForgeGradle so modders don't need to manually do it. But that is later.
103107
sourceSets.forEach {
104108
val dir = layout.buildDirectory.dir("sourcesSets/${it.name}")
105109
it.output.setResourcesDir(dir)
106110
it.java.destinationDirectory.set(dir)
107111
}
112+
113+
shadowJar {
114+
archiveVersion = "$modVersion+$minecraftVersion"
115+
configurations = listOf(shadowBundle)
116+
archiveClassifier = "dev-shadow"
117+
}
118+
119+
remapJar {
120+
dependsOn(processResources, shadowJar)
121+
inputFile = shadowJar.get().archiveFile
122+
}
108123
}

neoforge/build.gradle.kts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
val modVersion: String by project
2+
val minecraftVersion: String by project
13
val neoVersion: String by project
24
val kotlinForgeVersion: String by project
35

46
base.archivesName = "${base.archivesName.get()}-neoforge"
57

8+
plugins {
9+
id("com.github.johnrengelman.shadow") version "8.1.1"
10+
}
11+
612
architectury {
713
platformSetupLoomIde()
814
neoForge()
@@ -42,11 +48,6 @@ fun DependencyHandlerScope.setupConfigurations() {
4248
implementation(it)
4349
include(it)
4450
}
45-
46-
shadowBundle.dependencies.forEach {
47-
shadowCommon(it)
48-
shadow(it)
49-
}
5051
}
5152

5253
dependencies {
@@ -79,8 +80,14 @@ tasks {
7980
}
8081
}
8182

83+
shadowJar {
84+
archiveVersion = "$modVersion+$minecraftVersion"
85+
configurations = listOf(shadowBundle)
86+
archiveClassifier = "dev-shadow"
87+
}
88+
8289
remapJar {
83-
dependsOn(processResources)
84-
atAccessWideners.add("lambda.accesswidener") // Add the access widener to the remapper
90+
dependsOn(processResources, shadowJar)
91+
inputFile = shadowJar.get().archiveFile
8592
}
8693
}

0 commit comments

Comments
 (0)