[SOLVED] gradle version catalog classifier


This Content is from Stack Overflow. Question asked by Hakanai

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 {
                // ...

                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) {

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.


There is nothing in the version catalog to specify classifiers. You have to put the classifier in the dependency declaration:

implementation(variantOf(libs.netty-epoll-linux) { classifier("linux-x86_64") })

Frequently asked questions about version catalogs explains this design choice:

By design, version catalogs talk about dependency coordinates only. The choice of applying excludes is on the consumer side: for example, for a specific project, you might need to exclude a transitive dependency because you don’t use the code path which exercises this dependency, but this might not be the case for all places. Similarly, a classifier falls into the category of variant selectors: for the same dependency coordinates, one might want classifier X, another classifier Y, and it’s not necessarily allowed to have both in the same graph. Therefore, classifiers need to be declared on the dependency declaration site.

This Question was asked in StackOverflow by slesh and Answered by Kolargol00 It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?