Skip to content

Commit f07b0ea

Browse files
authored
Merge pull request #5 from Avanatiker/refactor/buildscript
Fix: Buildscript forge and fabric
2 parents b2c0708 + e1ea759 commit f07b0ea

File tree

22 files changed

+167
-355
lines changed

22 files changed

+167
-355
lines changed

build.gradle.kts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ val yarnMappings = property("yarn_mappings").toString()
1010
val libs = file("libs")
1111

1212
plugins {
13-
kotlin("jvm") version "1.9.22"
13+
kotlin("jvm") version "1.9.23"
1414
id("org.jetbrains.dokka") version "1.9.20"
1515
id("architectury-plugin") version "3.4-SNAPSHOT"
1616
id("dev.architectury.loom") version "1.5-SNAPSHOT" apply false
@@ -26,14 +26,8 @@ subprojects {
2626
apply(plugin = "org.jetbrains.dokka")
2727

2828
dependencies {
29-
if (path == ":quilt") {
30-
"minecraft"("com.mojang:minecraft:1.20.2")
31-
"mappings"("net.fabricmc:yarn:1.20.2+build.3:v2")
32-
}
33-
else {
34-
"minecraft"("com.mojang:minecraft:$minecraftVersion")
35-
"mappings"("net.fabricmc:yarn:$yarnMappings:v2")
36-
}
29+
"minecraft"("com.mojang:minecraft:$minecraftVersion")
30+
"mappings"("net.fabricmc:yarn:$yarnMappings:v2")
3731
}
3832

3933
if (path == ":common") return@subprojects
@@ -46,17 +40,20 @@ subprojects {
4640
isCanBeConsumed = false
4741
isCanBeResolved = true
4842
}
43+
4944
val shadow = named<ShadowJar>("shadowJar") {
5045
archiveVersion = versionWithMCVersion
5146
archiveClassifier.set("shadow")
5247
configurations = listOf(shadowCommon)
5348
}
49+
5450
named<RemapJarTask>("remapJar") {
5551
dependsOn(shadow)
5652
inputFile = shadow.flatMap { it.archiveFile }
5753
archiveVersion = versionWithMCVersion
5854
archiveClassifier = ""
5955
}
56+
6057
jar {
6158
enabled = false
6259
}

common/build.gradle.kts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
val fabricLoaderVersion = property("fabric_loader_version").toString()
2-
val fabricKotlinVersion = property("fabric_kotlin_version").toString()
32
val mixinExtrasVersion = property("mixinextras_version").toString()
3+
val kotlinVersion = property("kotlin_version").toString()
4+
val kotlinxCoroutinesVersion = property("kotlinx_coroutines_version").toString()
45
val architecturyVersion = property("architectury_version").toString()
56

6-
architectury { common("fabric", "forge", "neoforge", "quilt") }
7+
architectury { common("fabric", "forge", "neoforge") }
78

89
loom {
910
silentMojangMappingsLicense()
@@ -12,24 +13,18 @@ loom {
1213

1314
repositories {
1415
maven("https://maven.fabricmc.net/")
15-
maven("https://jitpack.io")
16-
17-
mavenCentral()
18-
mavenLocal()
1916
}
2017

2118
dependencies {
2219
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
2320
// Do NOT use other classes from fabric loader
2421
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
2522

26-
// Remove the following line if you don't want to depend on the API
27-
modApi("dev.architectury:architectury:$architecturyVersion")
28-
2923
// Add dependencies on the required Kotlin modules.
30-
modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion")
3124
implementation("org.reflections:reflections:0.10.2")
32-
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!)
25+
26+
// Add Kotlin
27+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
3328
}
3429

3530
// Avoid nested jars

common/src/main/kotlin/com/lambda/Lambda.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ package com.lambda
22

33
import com.google.gson.Gson
44
import com.google.gson.GsonBuilder
5-
import com.lambda.config.serializer.*
6-
import com.lambda.module.tag.ModuleTag
7-
import com.lambda.util.KeyCode
8-
import dev.architectury.platform.Platform
5+
import com.lambda.config.serializer.BlockPosSerializer
6+
import com.lambda.config.serializer.BlockSerializer
7+
import com.lambda.config.serializer.ColorSerializer
98
import net.minecraft.block.Block
109
import net.minecraft.client.MinecraftClient
1110
import net.minecraft.util.math.BlockPos
12-
import org.apache.logging.log4j.Level
1311
import org.apache.logging.log4j.LogManager
14-
import org.apache.logging.log4j.core.Logger
12+
import org.apache.logging.log4j.Logger
1513
import java.awt.Color
1614

1715

@@ -20,14 +18,11 @@ object Lambda {
2018
const val MOD_ID = "lambda"
2119
const val SYMBOL = "λ"
2220
val VERSION: String = LoaderInfo.getVersion()
23-
val LOG = (LogManager.getLogger(SYMBOL) as Logger)
24-
.apply { level = if (Platform.isDevelopmentEnvironment()) Level.DEBUG else Level.INFO }
25-
@JvmStatic val mc: MinecraftClient by lazy { MinecraftClient.getInstance() }
21+
val LOG: Logger = LogManager.getLogger(SYMBOL)
22+
val mc: MinecraftClient by lazy { MinecraftClient.getInstance() }
2623

2724
val gson: Gson = GsonBuilder()
2825
.setPrettyPrinting()
29-
.registerTypeAdapter(ModuleTag::class.java, ModuleTagSerializer)
30-
.registerTypeAdapter(KeyCode::class.java, KeyCodeSerializer)
3126
.registerTypeAdapter(Color::class.java, ColorSerializer)
3227
.registerTypeAdapter(BlockPos::class.java, BlockPosSerializer)
3328
.registerTypeAdapter(Block::class.java, BlockSerializer)

common/src/main/kotlin/com/lambda/Loader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ object Loader {
2929

3030
LOG.info("${Lambda.MOD_NAME} ${Lambda.VERSION} was successfully initialized (${initTime}ms)")
3131
}
32-
}
32+
}

common/src/main/kotlin/com/lambda/command/CommandManager.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ object CommandManager : Configurable(LambdaConfig), Loadable {
116116
override fun load(): String {
117117
Reflections(
118118
ConfigurationBuilder()
119-
.setUrls(ClasspathHelper.forPackage("com.lambda.command.commands"))
119+
// Let's hope the maintainer of the library releases a new version soon
120+
// because this is horrible, it takes multiple SECONDS to scan the classpath,
121+
// and it's not even that big
122+
//
123+
// The culprit may be due to [ClasspathHelper.forClassLoader()] loading
124+
// the classes from the main thread while we are in a different thread.
125+
// If this is the case I wish the maintainer a very bad day.
126+
.addUrls(ClasspathHelper.forJavaClassPath())
127+
.addUrls(ClasspathHelper.forClassLoader())
128+
.filterInputsBy { it.contains("lambda") }
129+
.forPackage("com.lambda.command.commands")
120130
.setScanners(Scanners.SubTypes)
121131
).getSubTypesOf(LambdaCommand::class.java).forEach { commandClass ->
122132
commandClass.declaredFields.find {
@@ -131,4 +141,4 @@ object CommandManager : Configurable(LambdaConfig), Loadable {
131141

132142
return "Registered ${commands.size} commands"
133143
}
134-
}
144+
}

common/src/main/kotlin/com/lambda/module/ModuleRegistry.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import org.reflections.scanners.Scanners
77
import org.reflections.util.ClasspathHelper
88
import org.reflections.util.ConfigurationBuilder
99

10+
11+
1012
/**
1113
* The [ModuleRegistry] object is responsible for managing all [Module] instances in the system.
1214
*
@@ -21,8 +23,18 @@ object ModuleRegistry : Loadable {
2123
override fun load(): String {
2224
Reflections(
2325
ConfigurationBuilder()
24-
.setUrls(ClasspathHelper.forPackage("com.lambda.module.modules"))
25-
.setScanners(Scanners.SubTypes)
26+
// Let's hope the maintainer of the library releases a new version soon
27+
// because this is horrible, it takes multiple SECONDS to scan the classpath,
28+
// and it's not even that big
29+
//
30+
// The culprit may be due to [ClasspathHelper.forClassLoader()] loading
31+
// the classes from the main thread while we are in a different thread.
32+
// If this is the case I wish the maintainer a very bad day.
33+
.addUrls(ClasspathHelper.forJavaClassPath())
34+
.addUrls(ClasspathHelper.forClassLoader())
35+
.filterInputsBy { it.contains("lambda") }
36+
.forPackage("com.lambda.module.modules")
37+
.addScanners(Scanners.SubTypes)
2638
).getSubTypesOf(Module::class.java).forEach { moduleClass ->
2739
moduleClass.declaredFields.find {
2840
it.name == "INSTANCE"
@@ -36,4 +48,4 @@ object ModuleRegistry : Loadable {
3648

3749
return "Registered ${modules.size} modules with ${modules.sumOf { it.settings.size }} settings"
3850
}
39-
}
51+
}

common/src/main/kotlin/com/lambda/util/FolderRegister.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.lambda.util
22

3+
import com.lambda.Lambda.mc
34
import com.lambda.util.FolderRegister.config
45
import com.lambda.util.FolderRegister.lambda
56
import com.lambda.util.FolderRegister.minecraft
6-
import dev.architectury.platform.Platform
77
import java.io.File
88

99
/**
@@ -14,7 +14,7 @@ import java.io.File
1414
* @property config The directory for storing configuration files, located within the Lambda directory.
1515
*/
1616
object FolderRegister {
17-
val minecraft: File = Platform.getGameFolder().toFile()
17+
val minecraft: File = mc.runDirectory
1818
val lambda: File = File(minecraft, "lambda")
1919
val config: File = File(lambda, "config")
2020
}

fabric/build.gradle.kts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
val fabricLoaderVersion = property("fabric_loader_version").toString()
22
val fabricApiVersion = property("fabric_api_version").toString()
3-
val fabricKotlinVersion = property("fabric_kotlin_version").toString()
43
val architecturyVersion = property("architectury_version").toString()
4+
val kotlinFabricVersion = property("kotlin_fabric_version").toString()
55

66
architectury {
77
platformSetupLoomIde()
@@ -32,26 +32,21 @@ fun DependencyHandlerScope.setupConfigurations() {
3232

3333
includeMod.dependencies.forEach {
3434
modImplementation(it)
35+
include(it)
3536
}
3637
}
3738

3839
dependencies {
3940
// Fabric API (Do not touch)
4041
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
41-
modApi("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion")
42-
43-
// Remove the following line if you don't want to depend on the API
44-
modApi("dev.architectury:architectury-fabric:$architecturyVersion")
45-
46-
// Kotlin for Fabric
47-
modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion")
4842

4943
// Add dependencies on the required Kotlin modules.
5044
includeLib("org.reflections:reflections:0.10.2")
51-
includeLib("org.javassist:javassist:3.27.0-GA")
45+
includeLib("org.javassist:javassist:3.28.0-GA")
5246

5347
// Add mods to the mod jar
54-
// includeMod(...)
48+
includeMod("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion")
49+
includeMod("net.fabricmc:fabric-language-kotlin:$kotlinFabricVersion")
5550

5651
// Common (Do not touch)
5752
common(project(":common", configuration = "namedElements")) { isTransitive = false }
@@ -70,7 +65,7 @@ tasks {
7065
expand(getProperties())
7166
expand(mutableMapOf(
7267
"group" to project.group,
73-
"version" to project.version
68+
"version" to project.version,
7469
))
7570
}
7671
}

fabric/src/main/resources/fabric.mod.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
"lambda.mixins.common.json"
2727
],
2828
"depends": {
29-
"fabricloader": ">=0.14.24",
30-
"fabric-api": ">=0.83.0+1.20",
31-
"architectury": ">=9.0.6",
32-
"minecraft": ">=1.20.0",
33-
"java": ">=17",
34-
"fabric-language-kotlin": ">=${fabric_kotlin_version}"
29+
"fabricloader": ">=0.15.1",
30+
"fabric-api": ">=0.91.3+1.20.4",
31+
"minecraft": "1.20.4",
32+
"fabric-language-kotlin": ">=${kotlin_fabric_version}",
33+
"java": ">=17"
3534
}
3635
}

forge/build.gradle.kts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
val forgeVersion = property("forge_version").toString()
2-
val kotlinForgeVersion = property("kotlin_forge_version").toString()
32
val architecturyVersion = property("architectury_version").toString()
43
val mixinExtrasVersion = property("mixinextras_version").toString()
4+
val kotlinForgeVersion = property("kotlin_forge_version").toString()
55

66
architectury {
77
platformSetupLoomIde()
@@ -18,23 +18,11 @@ loom {
1818
extraAccessWideners.add(loom.accessWidenerPath.get().asFile.name)
1919
mixinConfig("lambda.mixins.common.json")
2020
}
21-
22-
mods {
23-
register("forge") {
24-
sourceSet("main", project(":forge"))
25-
26-
sourceSets.forEach {
27-
val dir = layout.buildDirectory.dir("sourcesSets/${it.name}")
28-
it.output.setResourcesDir(dir)
29-
it.java.destinationDirectory.set(dir)
30-
}
31-
}
32-
}
3321
}
3422

3523
repositories {
36-
maven("https://thedarkcolour.github.io/KotlinForForge/")
3724
maven("https://cursemaven.com")
25+
maven("https://thedarkcolour.github.io/KotlinForForge/")
3826
}
3927

4028
val common: Configuration by configurations.creating {
@@ -45,43 +33,40 @@ val common: Configuration by configurations.creating {
4533

4634
val includeLib: Configuration by configurations.creating
4735
val includeMod: Configuration by configurations.creating
36+
val shadowInclude: Configuration by configurations.creating
4837

4938
fun DependencyHandlerScope.setupConfigurations() {
5039
includeLib.dependencies.forEach {
51-
implementation(it)
40+
forgeRuntimeLibrary(it)
5241
include(it)
5342
}
5443

55-
// Please look at this before yelling at me
56-
// https://docs.architectury.dev/loom/using_libraries/
5744
includeMod.dependencies.forEach {
58-
implementation(it)
5945
forgeRuntimeLibrary(it)
46+
include(it)
6047
}
6148
}
6249

6350
dependencies {
6451
// Forge API
6552
forge("net.minecraftforge:forge:$forgeVersion")
6653

67-
// Remove the following line if you don't want to depend on the API
68-
modApi("dev.architectury:architectury-forge:$architecturyVersion")
69-
7054
// Add dependencies on the required Kotlin modules.
7155
includeLib("org.reflections:reflections:0.10.2")
72-
includeLib("org.javassist:javassist:3.27.0-GA")
73-
74-
implementation("io.github.llamalad7:mixinextras-forge:$mixinExtrasVersion")
75-
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!)
56+
includeLib("org.javassist:javassist:3.28.0-GA")
7657

7758
// Add mods to the mod jar
7859
includeMod("thedarkcolour:kotlinforforge:$kotlinForgeVersion")
7960

80-
// Bugfixes
81-
compileOnly(kotlin("stdlib")) // Hack https://github.com/thedarkcolour/KotlinForForge/issues/93
61+
// MixinExtras
62+
implementation("io.github.llamalad7:mixinextras-forge:$mixinExtrasVersion")
63+
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!)
64+
65+
// Fix KFF
66+
compileOnly(kotlin("stdlib"))
8267

8368
// Common (Do not touch)
84-
common(project(":common", configuration = "namedElements")) { isTransitive = false } // We cannot common here because it is treated as a different mod and forge will panic
69+
common(project(":common", configuration = "namedElements")) { isTransitive = false }
8570
shadowCommon(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false }
8671

8772
// Finish the configuration
@@ -90,11 +75,21 @@ dependencies {
9075

9176
tasks {
9277
processResources {
78+
inputs.property("group", project.group)
9379
inputs.property("version", project.version)
9480

9581
filesMatching("META-INF/mods.toml") {
9682
expand(getProperties())
97-
expand(mutableMapOf("version" to project.version))
83+
expand(mutableMapOf(
84+
"group" to project.group,
85+
"version" to project.version,
86+
))
9887
}
9988
}
89+
90+
sourceSets.forEach {
91+
val dir = layout.buildDirectory.dir("sourcesSets/${it.name}")
92+
it.output.setResourcesDir(dir)
93+
it.java.destinationDirectory.set(dir)
94+
}
10095
}

0 commit comments

Comments
 (0)