ForgeGradle icon indicating copy to clipboard operation
ForgeGradle copied to clipboard

add dependency with classifier?

Open KaitlynEthylia opened this issue 11 months ago • 3 comments

I'm trying to add the slim version of MixinExtras, but if I just add :slim to the end, I get an error telling me "Cannot add attributes or capabilities on a dependency that specifies artifacts or configuration information" and I haven't been able to figure out any other way to do it

KaitlynEthylia avatar Jan 14 '25 14:01 KaitlynEthylia

Can you send me an example of even your entire buildscript so I can reproduce? In my own projects I just Jar-in-Jar the main MixinExtras jar.

Jonathing avatar Jan 14 '25 15:01 Jonathing

Ok, I just tested this myself and am getting this problem. It looks like another implementation detail in ForgeGradle 6 where because jarJar is a configuration type, the data for how to handle those dependencies are stored as attributes. And you can't store attributes on module dependencies that specify specific classifiers or artifacts, because Gradle tends to use attributes to resolve those artifacts itself.

The icing on the cake is that ForgeGradle 6 has fallbacks in place if you don't set the version. For example, if you don't call jarJar.ranged(), what is SUPPOSED to happen is ForgeGradle makes a version for you like this: [${version},). However, this doesn't happen, and the only thing returned in version, resulting in the ranged version format error throwing.

So yeah, it's a complete fucking mess. The best I can do is fix the that one bug I mentioned above where the JarJar metadata defaults to having a ranged version of version and not [version,), so that if you don't call jarJar.pin() or jarJar.ranged(), it will still work. I've spent hours today trying to find some sort of suitable workaround, but I can't find any way of arbitrarily asking Gradle to use a specific classifier of a jar through a normal ModuleDependency.

Jonathing avatar Jan 16 '25 00:01 Jonathing

Yeah scratch that, this issue is a lot more deep-rooted than I thought. It turns out that even after my makeshift fix of defaulting the version range, JarJar will still use the unclassified jar to put into the jar file. So yeah, I'm completely out of options for this. I'll just make sure to keep this in mind when I work on newer Gradle-related projects.

Jonathing avatar Jan 16 '25 01:01 Jonathing

This can now be accomplished using the JarJar Gradle plugin, compatible with ForgeGradle 7 Beta.

compileOnly annotationProcessor('io.github.llamalad7:mixinextras-common:0.5.0')
runtimeOnly(jarJar('io.github.llamalad7:mixinextras-forge:0.5.0:slim')) {
    jarJar.configure(it) {
        range = '[0.5,)'
    }
}

I will publish a beta MDK using this in the near future.

Jonathing avatar Oct 02 '25 13:10 Jonathing