How do I get an artifact with a classifier when using Gradle version catalogs in a Kotlin project?

Viewed 19

I'm trying to set up a Kotlin project which wants some runtime-only dependencies, but those dependencies come from a classifier.

I'm using a libs.versions.toml catalog file to store all the versions, but Gradle decided that the catalog file can't store classifier info, so now I'm trying to find a way to specify it that doesn't use the catalog.

kotlin {
    // ...
    sourceSets {
        val jvmMain by getting {
            dependencies {
                // ...
                implementation(libs.lwjgl)
                implementation(libs.lwjgl.openvr)

                runtimeOnly(libs.lwjgl.openvr) // but want classifier = "native-windows"
            }
        }
        val jvmTest by getting
    }
}

Tried so far

  1. On a Gradle ticket, they say it would be this:
runtimeOnly(libs.lwjgl.openvr) {
    artifact {
        classifier = "native-windows"
    }
}

However, this does not work, as there is no overload for runtimeOnly which takes both an Any and a configuration action. If I provide it as a string, it works, but then I'm not using the version catalog anymore.

  1. The similar question answered here would have me use this:
implementation(variantOf(libs.lwjgl.openvr) {
    classifier("native-windows")
})

However, this doesn't appear to be valid either - No variantOf function exists, I can't find anywhere to import it from, and nobody thus far has said where they got it from.

  1. I then tried the usual hack of breaking out things like .apply{}... but it doesn't look like the type of the object I get at any point is the right type to be able to set the classifier.

So I'm out of ideas, short of discarding the catalogs feature in yet another project because it's blocking me doing anything useful.

Versions in play:

  • Gradle 7.5.1
  • Kotlin Multiplatform Plugin 1.6.10
0 Answers
Related