Skip to content

Improve test-classpath configuration for split environment #1060

@LCLPYT

Description

@LCLPYT

Context

I recently wanted to add unit tests to my mod.
In the project, loom is configured with splitEnvironmentSourceSets().

When trying to run the gradle 'test' task, I get the following error:

Minecraft game provider couldn't locate the game! The game may be absent from the class path, lacks some expected files, suffers from jar corruption or is of an unsupported variety/version.

The issue is, that the game common and environment jars are not in the class path.
I fixed the issue by manually adding this to my buildscript:

configurations {
    // common
    testCompileClasspath.extendsFrom(minecraftCommonNamedCompile)
    testRuntimeClasspath.extendsFrom(minecraftCommonNamedRuntime)
    // client only
    testCompileClasspath.extendsFrom(minecraftClientOnlyNamedCompile)
    testRuntimeClasspath.extendsFrom(minecraftClientOnlyNamedRuntime)
}

Now, game provider works, but this error occurs instead:

...
Caused by: java.lang.IllegalArgumentException: The specified resource 'fabric-networking-api-v1.client.mixins.json' was invalid or could not be read
	at org.spongepowered.asm.mixin.transformer.MixinConfig.create(MixinConfig.java:1290)
	at org.spongepowered.asm.mixin.transformer.Config.create(Config.java:148)
	... 41 more

The client mixin files cannot be found (the actual file is different sometimes).
I fixed this by adding this to my build.gradle:

configurations {
    testRuntimeClasspath.extendsFrom(modRuntimeClasspathClientMapped)
}

Then, everything is working as expected for my client+server project.

For server-only projects

One of my other mods is configured with serverOnlyMinecraftJar().
When executing the unit tests, the same game provider error occurs.
I fixed it with:

configurations {
    testCompileClasspath.extendsFrom(minecraftCommonNamedCompile)
    testRuntimeClasspath.extendsFrom(minecraftCommonNamedRuntime)
}

However, the error with the mixins does not occur.

Issue

This manual classpath configuration is a little confusing for mod developers who want to test their code with unit tests, especially when they don't know Gradle well...

Maybe loom could automatically do this configuration for projects with splitEnvironmentSourceSets() or serverOnlyMinecraftJar()?
I am pretty sure that clientOnlyMinecraftJar() needs extra configuration too.
At the very least, I think this should be documented somewhere.

Cheers

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions