GTNewHorizons/ExampleMod1.7.10

genIntellijRuns problems and a hacky fix

Closed this issue · 0 comments

It seems like genIntellijRuns may cause more issues than help for the way this build script is set up?

In some tutorials it's suggested that you should run gradle task during IDE setup. It creates two application configurations like so:
image

The benefit is you can add more CLI arguments to the launch, however, when you run the tasks it skips over the token replacement section.

As a result if you use this method you end up with modinfo like:
image

And end up with potential crashes like the following with the default proxy setup:

cpw.mods.fml.common.LoaderException: java.lang.ClassNotFoundException: GRADLETOKEN_GROUPNAME.ClientProxy
...
Caused by: java.lang.ClassNotFoundException: GRADLETOKEN_GROUPNAME.ClientProxy


cpw.mods.fml.common.LoaderException: java.lang.ClassNotFoundException: GRADLETOKEN_GROUPNAME.CommonProxy
...
Caused by: java.lang.ClassNotFoundException: GRADLETOKEN_GROUPNAME.CommonProxy

Solutions to the task existing

I don't know what I'm doing with gradle build scripts honestly, if it's possible to make it so the application configurations also run the token replacement they're currently missing

    if (replaceGradleTokenInFile) {
        replaceIn replaceGradleTokenInFile
        if (gradleTokenModId) {
            replace gradleTokenModId, modId
        }
        if (gradleTokenModName) {
            replace gradleTokenModName, modName
        }
        if (gradleTokenVersion) {
            replace gradleTokenVersion, modVersion
        }
        if (gradleTokenGroupName) {
            replace gradleTokenGroupName, modGroup
        }
    }

It may be worth just throwing a deprecation warning any time you run genIntellijRuns pointing people to the other way.

The other way

  1. In Intellij on gradle menu click on Tasks → forgegradle → runClient (It doesn't matter if you want to debug)
    image
  2. Now click on the task dropdown and select Edit Configurations
    image
  3. And hit the little Save icon to prevent the task from running away.
    image
  4. You can now select that task and use Debug to hot swap code with Ctrl+Shift+F9 to your hearts content.
    image

The only problem with this version is you can't add CLI arguments as easily, but if you really need to you can edit build.gradle and edit the following section, for example:

runClient {
    if (developmentEnvironmentUserName) {
        arguments += [
            "--username", developmentEnvironmentUserName,
            "--uuid", "7657b3d4cfd34078b523df0e1eb0f307",
            "--width", "1280",
            "--height", "720"
        ]
    }

    args(arguments)
    jvmArgs(jvmArguments)
}

Keep in mind that build.gradle is sometimes automatically updated and rewritten, so it may disappear or maybe they added a way to add cli arguments to build.properties in the future 🤷‍♂️

Mainly I just wanted to create this issue to help whoever else comes by later and give them a nice googleable bit of information that I lost a bunch of time to fixing it.