ModdingX / ModGradle

ModGradle adds some gradle plugins useful for creating forge mods.
Apache License 2.0
3 stars 0 forks source link

SourceJar plugin needs to be applied after setting java toolchain version #17

Open Jonathing opened 1 year ago

Jonathing commented 1 year ago

Probably due to how a ClasspathExec task gets the java launcher convention during initialization, and that type of task is created when this plugin is applied. Not sure if it is really an issue, but I've decided to report it as such.

I've worked around it with my Plugin DSL setup by doing this:

plugins {
    // ...
    id 'org.moddingx.modgradle.sourcejar' version '[4,5)' apply false
    // ...
}

// setting version variable and other mundane stuff...

java.toolchain.languageVersion = JavaLanguageVersion.of(17)

apply plugin: 'org.moddingx.modgradle.sourcejar'

// everything else...

If you're curious, here's my settings.gradle setup:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            // ModGradle
            var plugin = requested.id.toString()
            if (plugin.startsWith('org.moddingx.modgradle.')) {
                useModule "org.moddingx:ModGradle:${requested.version}"
            }
        }
    }
    repositories {
        gradlePluginPortal()
        maven { url = 'https://maven.minecraftforge.net/' }
        maven { url = 'https://repo.spongepowered.org/maven' }
        maven { url = 'https://maven.parchmentmc.org' }
        maven { url = 'https://maven.moddingx.org' }
    }
}

plugins {
    id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
}

Gradle 8.1.1
ForgeGradle 6.0.11
ModGradle 4.0.4

noeppi-noeppi commented 1 year ago

This seems to be a ForgeGradle problem. ForgeGradle accesses the toolchain version directly in their task constructors instead of using a provider. The ClasspathExec task works fine and allows the toolchain version to be changed after it has been constructed.

See: https://github.com/MinecraftForge/ForgeGradle/blob/FG_6.0/src/common/java/net/minecraftforge/gradle/common/tasks/JarExec.java#L83-L86 https://github.com/MinecraftForge/ForgeGradle/blob/FG_6.0/src/common/java/net/minecraftforge/gradle/common/tasks/ExtractRangeMap.java#L30-L37