Skip to content

Commit fa50388

Browse files
authored
Merge pull request #1 from Avanatiker/refactor/buildscript
Refactor: Buildscripts
2 parents b2f11c8 + 26422a6 commit fa50388

File tree

20 files changed

+284
-72
lines changed

20 files changed

+284
-72
lines changed

build.gradle.kts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22
import net.fabricmc.loom.task.RemapJarTask
33

4-
val modId = project.properties["mod_id"].toString()
5-
val modVersion = project.properties["mod_version"].toString()
6-
val mavenGroup = project.properties["maven_group"].toString()
7-
val minecraftVersion = project.properties["minecraft_version"].toString()
8-
val yarnMappings = project.properties["yarn_mappings"].toString()
4+
val modId = property("mod_id").toString()
5+
val modVersion = property("mod_version").toString()
6+
val mavenGroup = property("maven_group").toString()
7+
val minecraftVersion = property("minecraft_version").toString()
8+
val yarnMappings = property("yarn_mappings").toString()
9+
10+
val libs = file("libs")
911

1012
plugins {
1113
kotlin("jvm") version "1.9.22"
@@ -22,6 +24,7 @@ architectury {
2224
subprojects {
2325
apply(plugin = "dev.architectury.loom")
2426
apply(plugin = "org.jetbrains.dokka")
27+
2528
dependencies {
2629
"minecraft"("com.mojang:minecraft:$minecraftVersion")
2730
"mappings"("net.fabricmc:yarn:$yarnMappings:v2")
@@ -66,19 +69,18 @@ allprojects {
6669
repositories {
6770
maven("https://api.modrinth.com/maven")
6871
maven("https://jitpack.io")
69-
maven("https://maven.shedaniel.me/") {
70-
name = "Architectury"
71-
}
72+
maven("https://maven.shedaniel.me/") { name = "Architectury" }
7273
maven("https://maven.terraformersmc.com/releases/")
73-
}
7474

75-
tasks {
76-
withType<JavaCompile> {
77-
options.encoding = "UTF-8"
78-
options.release = 17
79-
}
80-
compileKotlin {
81-
kotlinOptions.jvmTarget = "17"
75+
flatDir {
76+
dirs(libs)
8277
}
8378
}
79+
80+
java {
81+
// withSourcesJar() // Uncomment this line when the plugin system is ready
82+
83+
sourceCompatibility = JavaVersion.VERSION_17
84+
targetCompatibility = JavaVersion.VERSION_17
85+
}
8486
}

common/build.gradle.kts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
val fabricLoaderVersion = project.properties["fabric_loader_version"].toString()
2-
val fabricKotlinVersion = project.properties["fabric_kotlin_version"].toString()
3-
val mixinExtrasVersion = project.properties["mixinextras_version"].toString()
1+
val fabricLoaderVersion = property("fabric_loader_version").toString()
2+
val fabricKotlinVersion = property("fabric_kotlin_version").toString()
3+
val mixinExtrasVersion = property("mixinextras_version").toString()
4+
val kotlinXCoroutineVersion = property("kotlinx_coroutines_version").toString()
45

5-
architectury { common("fabric", "forge") }
6+
architectury { common("fabric", "forge", "neoforge") }
67

78
loom {
9+
silentMojangMappingsLicense()
810
accessWidenerPath.set(File("src/main/resources/lambda.accesswidener"))
911
}
1012

1113
repositories {
12-
maven("https://maven.fabricmc.net/") {
13-
name = "Fabric"
14-
}
14+
maven("https://maven.fabricmc.net/")
1515
maven("https://jitpack.io")
16+
1617
mavenCentral()
1718
mavenLocal()
1819
}
@@ -21,12 +22,14 @@ dependencies {
2122
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
2223
// Do NOT use other classes from fabric loader
2324
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
25+
2426
// Add dependencies on the required Kotlin modules.
2527
modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion")
2628
implementation("org.reflections:reflections:0.10.2")
2729
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!)
2830
}
2931

32+
// Avoid nested jars
3033
tasks.named("remapJar") {
3134
enabled = false
3235
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import org.apache.logging.log4j.LogManager
1313
import org.apache.logging.log4j.Logger
1414

1515
object Lambda {
16-
private const val MOD_NAME = "Lambda"
16+
const val MOD_NAME = "Lambda"
1717
const val MOD_ID = "lambda"
1818
private const val SYMBOL = "λ"
19-
private val VERSION: String = LoaderInfo.getVersion()
19+
val VERSION: String = LoaderInfo.getVersion()
2020

2121
val LOG: Logger = LogManager.getLogger(SYMBOL)
22-
val mc: MinecraftClient = MinecraftClient.getInstance()
22+
val mc: MinecraftClient by lazy { MinecraftClient.getInstance() }
23+
2324
val gson: Gson = GsonBuilder()
2425
.setPrettyPrinting()
2526
.registerTypeAdapter(BlockPos::class.java, BlockPosSerializer)
File renamed without changes.

common/src/main/kotlin/com/lambda/module/modules/BoringModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object BoringModule : Module(
2424
mapOf("One" to 1, "Two" to 2, "Three" to 3, "Four" to 4, "Five" to 5)
2525
)
2626
private val boringEnum by setting("Boring Enum", BoringEnum.ONE)
27-
private val blockSetting by setting("Boring Block", Blocks.STONE)
27+
//private val blockSetting by setting("Boring Block", Blocks.STONE) // Registries are not initialized yet
2828
private val blockPosSetting by setting("Boring BlockPos", BlockPos(420, 69, 1337))
2929
// private val blockListSetting by setting("Boring Block List", listOf(Blocks.STONE, Blocks.DIRT, Blocks.GRASS_BLOCK))
3030

@@ -49,4 +49,4 @@ object BoringModule : Module(
4949
LOG.info("I'm ${if (superBoring) "super boring ($boringValue)" else "boring"}! $isEnabled")
5050
}
5151
}
52-
}
52+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ object FolderRegister {
77
val minecraft: File = mc.runDirectory
88
val lambda: File = File(minecraft, "lambda")
99
val config: File = File(lambda, "config")
10-
}
10+
}

fabric/build.gradle.kts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
val fabricLoaderVersion = project.properties["fabric_loader_version"].toString()
2-
val fabricApiVersion = project.properties["fabric_api_version"].toString()
3-
val fabricKotlinVersion = project.properties["fabric_kotlin_version"].toString()
1+
val fabricLoaderVersion = property("fabric_loader_version").toString()
2+
val fabricApiVersion = property("fabric_api_version").toString()
3+
val fabricKotlinVersion = property("fabric_kotlin_version").toString()
44

55
architectury {
66
platformSetupLoomIde()
@@ -20,17 +20,39 @@ val common: Configuration by configurations.creating {
2020
configurations["developmentFabric"].extendsFrom(this)
2121
}
2222

23-
dependencies {
24-
common(project(":common", configuration = "namedElements")) {
25-
isTransitive = false
23+
val includeLib: Configuration by configurations.creating
24+
val includeMod: Configuration by configurations.creating
25+
26+
fun DependencyHandlerScope.setupConfigurations() {
27+
includeLib.dependencies.forEach {
28+
implementation(it)
29+
include(it)
2630
}
27-
shadowCommon(project(path = ":common", configuration = "transformProductionFabric")) {
28-
isTransitive = false
31+
32+
includeMod.dependencies.forEach {
33+
modImplementation(it)
2934
}
35+
}
36+
37+
dependencies {
38+
// Fabric API (Do not touch)
3039
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
3140
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion")
3241
modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion")
33-
implementation("org.reflections:reflections:0.10.2")
42+
43+
// Add dependencies on the required Kotlin modules.
44+
includeLib("org.reflections:reflections:0.10.2")
45+
includeLib("org.javassist:javassist:3.27.0-GA")
46+
47+
// Add mods to the mod jar
48+
// includeMod(...)
49+
50+
// Common (Do not touch)
51+
common(project(":common", configuration = "namedElements")) { isTransitive = false }
52+
shadowCommon(project(path = ":common", configuration = "transformProductionFabric")) { isTransitive = false }
53+
54+
// Finish the configuration
55+
setupConfigurations()
3456
}
3557

3658
tasks {

fabric/src/main/kotlin/com/lambda/fabric/LambdaFabric.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package com.lambda.fabric
33
import net.fabricmc.api.ClientModInitializer
44
import com.lambda.Lambda
55
import com.lambda.Lambda.LOG
6+
import com.lambda.Lambda.MOD_NAME
7+
import com.lambda.Lambda.VERSION
68

79
object LambdaFabric : ClientModInitializer {
810
override fun onInitializeClient() {
911
Lambda.initialize()
10-
11-
LOG.info("Lambda Fabric initialized")
12+
LOG.info("$MOD_NAME Fabric $VERSION initialized.")
1213
}
1314
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"lambda.mixins.common.json"
2727
],
2828
"depends": {
29-
"fabricloader": ">=${fabric_loader_version}",
30-
"fabric-api": "*",
31-
"minecraft": "1.20.4",
29+
"fabricloader": ">=0.14.24",
30+
"fabric-api": ">=0.83.0+1.20",
31+
"minecraft": ">=1.20.0",
3232
"java": ">=17",
3333
"fabric-language-kotlin": ">=${fabric_kotlin_version}"
3434
}

forge/build.gradle.kts

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
val forgeVersion = project.properties["forge_version"].toString()
2-
val kotlinForgeVersion = project.properties["kotlin_forge_version"].toString()
3-
val mixinExtrasVersion = project.properties["mixinextras_version"].toString()
1+
val forgeVersion = property("forge_version").toString()
2+
val kotlinForgeVersion = property("kotlin_forge_version").toString()
3+
val architecturyVersion = property("architectury_version").toString()
4+
val mixinExtrasVersion = property("mixinextras_version").toString()
45

56
architectury {
67
platformSetupLoomIde()
@@ -11,20 +12,29 @@ base.archivesName.set("${base.archivesName.get()}-forge")
1112

1213
loom {
1314
accessWidenerPath.set(project(":common").loom.accessWidenerPath)
15+
1416
forge {
1517
convertAccessWideners = true
1618
extraAccessWideners.add(loom.accessWidenerPath.get().asFile.name)
1719
mixinConfig("lambda.mixins.common.json")
1820
}
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+
}
1933
}
2034

2135
repositories {
22-
maven("https://thedarkcolour.github.io/KotlinForForge/") {
23-
name = "KotlinForForge"
24-
}
25-
maven("https://cursemaven.com") {
26-
name = "Curse"
27-
}
36+
maven("https://thedarkcolour.github.io/KotlinForForge/")
37+
maven("https://cursemaven.com")
2838
}
2939

3040
val common: Configuration by configurations.creating {
@@ -33,18 +43,49 @@ val common: Configuration by configurations.creating {
3343
configurations["developmentForge"].extendsFrom(this)
3444
}
3545

36-
dependencies {
37-
forge("net.minecraftforge:forge:$forgeVersion")
38-
implementation("thedarkcolour:kotlinforforge:$kotlinForgeVersion")
39-
common(project(":common", configuration = "namedElements")) {
40-
isTransitive = false
46+
val includeLib: Configuration by configurations.creating
47+
val includeMod: Configuration by configurations.creating
48+
49+
fun DependencyHandlerScope.setupConfigurations() {
50+
includeLib.dependencies.forEach {
51+
implementation(it)
52+
include(it)
4153
}
42-
shadowCommon(project(path = ":common", configuration = "transformProductionForge")) {
43-
isTransitive = false
54+
55+
// Please look at this before yelling at me
56+
// https://docs.architectury.dev/loom/using_libraries/
57+
includeMod.dependencies.forEach {
58+
implementation(it)
59+
forgeRuntimeLibrary(it)
4460
}
45-
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!)
46-
implementation(include("io.github.llamalad7:mixinextras-forge:$mixinExtrasVersion")!!)
47-
implementation("org.reflections:reflections:0.10.2")
61+
}
62+
63+
dependencies {
64+
// Forge API
65+
forge("net.minecraftforge:forge:$forgeVersion")
66+
67+
// Architectury API
68+
modApi("dev.architectury:architectury-forge:$architecturyVersion")
69+
70+
// Add dependencies on the required Kotlin modules.
71+
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")!!)
76+
77+
// Add mods to the mod jar
78+
includeMod("thedarkcolour:kotlinforforge:$kotlinForgeVersion")
79+
80+
// Bugfixes
81+
compileOnly(kotlin("stdlib")) // Hack https://github.com/thedarkcolour/KotlinForForge/issues/93
82+
83+
// 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
85+
shadowCommon(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false }
86+
87+
// Finish the configuration
88+
setupConfigurations()
4889
}
4990

5091
tasks {

0 commit comments

Comments
 (0)