- fix: NullPointerException when the config class of mod updated

- alter: better test code in `common/src/test`, `neoforge/src/test` and `fabric/src/test`, run `Test Minecraft Client(:fabric)` or `Test Minecraft Client(:neoforge)` for testing
This commit is contained in:
Jaffe2718
2025-09-11 11:48:26 +08:00
parent 78c462dc1c
commit c775a9d221
18 changed files with 167 additions and 62 deletions

View File

@@ -13,11 +13,44 @@ repositories {
architectury {
platformSetupLoomIde()
neoForge()
neoForge {
platformPackage = "neoforge"
}
}
sourceSets {
test {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
java {
srcDirs.add('src/test/java' as File)
}
resources {
srcDirs.add('src/test/resources' as File)
}
}
}
loom {
accessWidenerPath = project(":common").loom.accessWidenerPath
runs {
testClient {
client()
name = "Test Minecraft Client"
mods {
create('midnightlib') {
sourceSet sourceSets.main
}
create('modid') { // test mod
sourceSet sourceSets.test
}
}
source sourceSets.test
}
}
}
configurations {
@@ -44,6 +77,10 @@ dependencies {
common(project(path: ':common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge')
// testImplementation common(project(path: ':common', configuration: 'namedElements')) { transitive false }
testImplementation common(project(path: ':common', configuration: 'testOutput')) { transitive false }
testImplementation sourceSets.main.output
}
processResources {
@@ -54,6 +91,14 @@ processResources {
}
}
processTestResources {
inputs.property 'version', rootProject.version
filesMatching('META-INF/neoforge.mods.toml') {
expand version: rootProject.version
}
}
shadowJar {
configurations = [project.configurations.shadowBundle]
archiveClassifier = 'dev-shadow'
@@ -105,4 +150,4 @@ unifiedPublishing {
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
package eu.midnightdust.test.neoforge;
import eu.midnightdust.test.config.MidnightConfigExample;
import net.neoforged.fml.common.Mod;
@Mod(MLExampleNeoForge.MODID)
public class MLExampleNeoForge {
public static final String MODID = "modid";
public MLExampleNeoForge() {
MidnightConfigExample.init(MODID, MidnightConfigExample.class);
}
}

View File

@@ -0,0 +1,34 @@
modLoader = "javafml"
loaderVersion = "[2,)"
#issueTrackerURL = ""
license = "MIT License"
[[mods]]
modId = "modid"
version = "${version}"
displayName = "MidnightLib Test Mod"
authors = "TeamMidnightDust, Motschen"
description = '''
Example Mod for Team MidnightDust's mods.
'''
[[dependencies.modid]]
modId = "neoforge"
mandatory = true
versionRange = "[20.5,)"
ordering = "NONE"
side = "BOTH"
[[dependencies.modid]]
modId = "minecraft"
mandatory = true
versionRange = "[1.20.5,)"
ordering = "NONE"
side = "BOTH"
[[dependencies.modid]]
modId = "midnightlib"
mandatory = true
versionRange = "[1.0,)"
ordering = "NONE"
side = "BOTH"