fabric-loom icon indicating copy to clipboard operation
fabric-loom copied to clipboard

[GenEclipseRuns] Embed the runtime classpath from gradle into the run configs

Open Sollace opened this issue 1 year ago • 1 comments

Background: Gradle and Eclipse don't really treat classpaths in the same way. Where gradle has separate classpaths for compile-time dependencies, runtime-dependencies, and test-dependencies, Eclipse only really has one project-level classpath and it expects each run config to instead provide its own classpath.

Since gradle's task doesn't attempt to generate run configurations for Eclipse, it ends up just merging all of its classpaths into one and it dumps that in as the project's global classpath, but that creates a lot of problems, particularly with dependencies pulled in with modCompileOnly ending up loaded at runtime, and in the case of projects that provide a "working" version and an "api" version, running the game ends up with both of them being loaded which creates clashes.

What I'm suggesting to fix this problem is as such:

Just generate your own classpaths.

Loom has access to the classpaths gradle is working with, and since loom is also generating run configs, it only makes sense that it would also generate the correct runtime classpath and add them into the run configurations so at least when you launch the game it's not going to pull in dependencies that aren't meant to be loaded in at runtime.

It won't fix the problem of them being visible in the editor, but it will at least prevent issues when actually debugging, and if you do end up referencing something from a runtime-only dependency in your code, you'd very quickly become aware of this since the game then wouldn't run when you debug it (rather than testing it, thinking it's fine, then only finding the problem later when you attempt to build it through gradle).

I've done ahead and attached an example launch config that specifies its own classpath so we have something to reference for the format. It seems to just be the normal format used in the .classpath file, just with each line escaped so it can be inserted in as entries to the xml file.

example-launch-config.txt

Sollace avatar Jul 05 '23 23:07 Sollace

Relevant discord discussion: https://discord.com/channels/507304429255393322/592749519171616796/1126282616874741921

Sollace avatar Jul 05 '23 23:07 Sollace