Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test-classpath configuration for split environment #1060

Open
LCLPYT opened this issue Mar 3, 2024 · 0 comments · Fixed by #1179
Open

Improve test-classpath configuration for split environment #1060

LCLPYT opened this issue Mar 3, 2024 · 0 comments · Fixed by #1179
Milestone

Comments

@LCLPYT
Copy link

LCLPYT commented Mar 3, 2024

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

@modmuss50 modmuss50 added this to the 1.7 milestone Apr 6, 2024
@modmuss50 modmuss50 modified the milestones: 1.7, 1.8 Jun 14, 2024
modmuss50 added a commit to modmuss50/fabric-loom-1 that referenced this issue Sep 26, 2024
Fixes FabricMC#1060

Also added a tool to extract test projects to make them easier to work on.
@modmuss50 modmuss50 linked a pull request Sep 26, 2024 that will close this issue
modmuss50 added a commit that referenced this issue Sep 26, 2024
* Setup the test sourceset better when using split sources.

Fixes #1060

Also added a tool to extract test projects to make them easier to work on.

* Fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants