neoforged / NeoGradle

Gradle plugin for NeoForge development
GNU Lesser General Public License v2.1
47 stars 24 forks source link

Issues migrating multi-project build with Game Library to NG 7+ #64

Closed darkevilmac closed 4 months ago

darkevilmac commented 11 months ago

I'm currently working on migrating my mods over to the latest NeoForge versions and am running into some issues with NeoGradle 7 that I wasn't having on older versions.

My current setup uses two projects, one of which is the game library that I distribute - Compound, and the other is the test mod used to validate the functions of the library - Molecule.

The way I have the project organized is a child project for Compound, and a parent project for Molecule that adds the Compound project as a dependency. I had this working previously using compileOnly and by specifying the source set for my mod to include the child project. You can see this configuration here: https://github.com/tridentmc/molecule/tree/1.20

I've tried to adjust this to match the changes that were made to NeoGradle, including using the runtime dependency system introduced in a recent PR - unfortunately this hasn't really given me much success. You can see my current setup here: https://github.com/tridentmc/molecule/tree/1.20.2

As of right now I get errors related to task dependencies: https://gist.github.com/darkevilmac/c8b349ac16092282e72a418c004b2831

I attempted to put a fix in place for this based on the error log

import net.neoforged.gradle.userdev.runtime.tasks.ClasspathSerializer
import net.neoforged.gradle.common.tasks.ArtifactFromOutput

tasks.withType(ClasspathSerializer).configureEach {
    var compound = project(':Compound')
    var compoundTasks = compound.tasks.withType(ArtifactFromOutput)
    dependsOn(compoundTasks)
}

However this just results in an error related to missing NeoForge classes when running.

I'm somewhat at a loss here at this point, this feels like it might be a regression or I could just be missing something obvious.

Relevant ForgeGradle issues: https://github.com/MinecraftForge/ForgeGradle/issues/583 https://github.com/MinecraftForge/ForgeGradle/issues/557

Any help at all would be appreciated

Technici4n commented 11 months ago

Please see https://github.com/neoforged/NeoGradle/pull/52 instead for how to correctly replace game libraries.

darkevilmac commented 11 months ago

Please see #52 instead for how to correctly replace game libraries.

I have, you can see I'm using that system in my 1.20.2 branch

Technici4n commented 11 months ago

You shouldn't have to touch the ClasspathSerializer task.

Technici4n commented 11 months ago

I can maybe give your project a look in a few hours,

darkevilmac commented 11 months ago

I can maybe give your project a look in a few hours,

Thanks I appreciate it, I've updated the original post with a few relevant GitHub issues on ForgeGradle as well. Just to hopefully give context as to the setup I've been running with since then.

darkevilmac commented 11 months ago

If there's any additional info needed feel free to reach out.

marchermans commented 11 months ago

I did some research a bit internally:

  1. This will be fixed in the future on NeoGradle 7 sides. However, this won't fix your issue because running it with the fix will still not allow projects to be loaded. The problem is how project references are handled in classpath: They are directories. Directories can not be loaded as a mod from the classpath. As of writing, there is no plan to change that.
  2. However, This problem is solvable using modSources. On the run, this property was mainly designed to circumvent this problem. It can accept directories, and as such, you can use it in a multi-project workflow to load several projects: Add your second projects sourceset, or any sourceset you want to load as part of the run, to the modSources. But make sure that you have NG7 installed in all those projects so that their mod ids, and other bootstrap information can be collected passed along to the run.
darkevilmac commented 11 months ago
  1. This will be fixed in the future on NeoGradle 7 sides. However, this won't fix your issue because running it with the fix will still not allow projects to be loaded. The problem is how project references are handled in classpath: They are directories. Directories can not be loaded as a mod from the classpath. As of writing, there is no plan to change that.

I suppose just leave the issue for the time being until that fix is in place?

2. However, This problem is solvable using modSources. On the run, this property was mainly designed to circumvent this problem. It can accept directories, and as such, you can use it in a multi-project workflow to load several projects: Add your second projects sourceset, or any sourceset you want to load as part of the run, to the modSources. But make sure that you have NG7 installed in all those projects so that their mod ids, and other bootstrap information can be collected passed along to the run.

Gotcha, only concern here is that my other project isn't a mod, it's a library that depends on the game sources. I'm hoping that won't be an issue though?

Technici4n commented 11 months ago

It's fine yes. "Mod sources" here means stuff that should end up in the GAME layer.

darkevilmac commented 11 months ago

It's fine yes. "Mod sources" here means stuff that should end up in the GAME layer.

Gotcha, figured as much - just didn't want to wait and then find I have something else to resolve on top.

CreativeMD commented 11 months ago

I'm having the same issue. In my case it's a mod I need to add. However the suggested solution does not work for me. I added modSource project(":CreativeCore").sourceSets.main to my run configuration as suggested, but this results in a crash:

Exception in thread "main" java.lang.module.ResolutionException: Module creativecore contains package team.creative.creativecore.common.gui.integration, module main exports package team.creative.creativecore.common.gui.integration to creativecore
    at java.base/java.lang.module.Resolver.resolveFail(Resolver.java:901)
    at java.base/java.lang.module.Resolver.failTwoSuppliers(Resolver.java:807)
    at java.base/java.lang.module.Resolver.checkExportSuppliers(Resolver.java:736)
    at java.base/java.lang.module.Resolver.finish(Resolver.java:380)
    at java.base/java.lang.module.Configuration.<init>(Configuration.java:140)
    at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:494)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.9/cpw.mods.modlauncher.ModuleLayerHandler.buildLayer(ModuleLayerHandler.java:75)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.9/cpw.mods.modlauncher.TransformationServicesHandler.buildTransformingClassLoader(TransformationServicesHandler.java:60)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.9/cpw.mods.modlauncher.Launcher.run(Launcher.java:106)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.9/cpw.mods.modlauncher.Launcher.main(Launcher.java:78)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.9/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.9/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)
    at cpw.mods.bootstraplauncher@1.1.2/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141)

The entire run configuration

runs {  
    configureEach {
        workingDirectory project.file('run')
        systemProperty 'forge.logging.console.level', 'debug'

        modSource project.sourceSets.main
        modSource project(":CreativeCore").sourceSets.main
    }

    client {
    }
}

Am I doing something wrong? Also tried to use dependencies as pointed out here https://github.com/neoforged/NeoGradle/pull/52. In that case the game starts, but CreativeCore is not loaded at all.

Technici4n commented 11 months ago

Make sure that you set the same mod identifier on all the source sets.

CreativeMD commented 10 months ago

Make sure that you set the same mod identifier on all the source sets.

Not sure what exactly you mean.

Technici4n commented 10 months ago

All your source sets should have

runs {
        modIdentifier = name
    }

Might be best to ask on discord in the #modder-support-gradle channel.

marchermans commented 4 months ago

This has been fixed, see https://github.com/neoforged/NeoGradle?tab=readme-ov-file#including-the-sibling-project-in-your-run. Specifically the add('....', sourceSet) variant.