Gradle Version Catalog and JavaFX Dependencies - Classifier

I am currently testing Version Catalog on a JavaFX project of mine. Therefore I need to update the dependencies and found something where I am stuck.

My dependencies are looking like this:

dependencies {
    implementation("org.openjfx:javafx-base:11.0.2:win")
    implementation("org.openjfx:javafx-fxml:11.0.2:win")
    implementation("org.openjfx:javafx-graphics:11.0.2:win")
    implementation("org.openjfx:javafx-controls:11.0.2:win")
    implementation("org.openjfx:javafx-web:11.0.2:win")
}

I’ve created a libs.versions.toml file to reference the
dependencies later

[versions]
javafx-win = "11.0.2:win"

[libraries]
javafx-base-win = { module = "org.openjfx:javafx-base", version.ref = "javafx-win" }
javafx-controls-win = { module = "org.openjfx:javafx-controls", version.ref = "javafx-win" }
javafx-fxml-win = { module = "org.openjfx:javafx-fxml", version.ref = "javafx-win" }
javafx-graphics-win = { module = "org.openjfx:javafx-graphics", version.ref = "javafx-win" }
javafx-media-win = { module = "org.openjfx:javafx-media", version.ref = "javafx-win" }
javafx-web-win = { module = "org.openjfx:javafx-web", version.ref = "javafx-win" }


[bundles]
javafx-win = ["javafx-base-win", "javafx-controls-win", "javafx-fxml-win", "javafx-graphics-win",
  "javafx-media-win", "javafx-web-win"]

The problem that occurs now is that the depdendencies could not be found e.g.

dependencies {
   implementation(libs.bundles.javafx.win)
}
> Could not find org.openjfx:javafx-base:11.0.2-win.
        Searched in the following locations:
          - https://repo.maven.apache.org/maven2/org/openjfx/javafx-base/11.0.2-win/javafx-base-11.0.2-win.pom
        If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
        Required by:
            project :

404 Not Found to the website: https://repo.maven.apache.org/maven2/org/openjfx/javafx-base/11.0.2-win/javafx-base-11.0.2-win.pom

Probably this path should be correct: Central Repository: org/openjfx/javafx-base/11.0.2

I would appreciate the help how I should configure the tomlfile.

Thanks in advance!

The classifier is not part of the version catalog.
There is no way to specify the classifier in the version catalog.
The classifier is part of the actual usage of the version catalog entry.

Thanks for the reply!

How does the notation looks like if i want to add a classifier when i use a version catalog entry?

implementation(variantOf(libs.foo) {
    classifier("bar")
})

thx for the reply. it didn’t work for me. I tried
implementation (variantOf(libs.log4j) {classifier(“sources”)})
which resulted in Could not find method variantOf() for arguments…

Works perfectly fine here.
How does the message continue after “arguments”?
Can you show an MCVE?

the complete message is

> Could not find method variantOf() for arguments [org.gradle.accessors.dm.LibrariesForLibs$Log4jLibraryAccessors@5b8d0fdd, build_9hi4efpzfo07zsuacu9s85ghk$_run_closure4$_closure26@59df85f] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

my Catalog looks like this
build.gralde of catalog project:

catalog {    versionCatalog {        alias("log4j").to("log4j", "log4j").version("1.2.16")    }}

the catalog is loaded via settings.gradle:

enableFeaturePreview("VERSION_CATALOGS")

dependencyResolutionManagement {
    repositories {        maven {url "${nexusUrl}/plugins/"}    }
    versionCatalogs {    libs {            from("de.finkonsens.muest:versionCatalog:+")        }    } 
}

builde gradle:

plugins {
    id "java"
    id "java-library"
    id "maven-publish"
}

dependencies {    implementation (variantOf(libs.log4j) {classifier("sources")}) }

thx for your patiance

Works perfectly fine here.
Again the question, can you please provide an MCVE?
I’m not asking for that for fun.
But there is probably something very specific you do wrong.

thx alot, i found it by reducing the catalog to 1 line
to get the sources i defined a source lib alias(“log4j-sources”).to(“log4j”, “log4j”).version(“1.2.16-sources”) that caused the error

i did also open a thread yesterday with exactly this catalog. My problem there is, if i edit the catalog, publish it to nexus i have to delete it from the cache first to see the changes. Is there anything i can do to prevent the catalog.jar from beeing cached?

Hello,
I have the same question as the OP.
I have a bundle defined in my toml catalog. But when I try to set a classifier using this syntax…

implementation (variantOf(libs.bundles.javaFxWinLibs) {
            classifier('win')
        })

I get this error message
Could not set unknown property 'classifier' for org.openjfx:javafx-base:17.0.8 of type org.gradle.api.internal.artifacts.dependencies.DefaultMutableMinimalDependency.

So the question is - is it possible to set a classifier for a bundle? And if yes what is the syntax please?
Thanks.

Actually, you should not request the classifier manually.
By that you for example loose the dependency information.
Since version 0.1.0 the JavaFX Gradle plugin was significantly improved to use a component metadata rule to properly model the OS-specific and architecture-specific artifacts as feature variants.
It even by default configures the runtime classpath and compile classpath of all source sets to the OS and architecture of the currently used operating system if you do not configure something manually and also easily allows to do cross-platform builds.

Ah ok, thanks very much for pointing me in the right direction regarding javafx; I will look into that.

My base question about the syntax for using classifiers with bundles still stands though as I have a couple of other examples with our own jars where we have the same problem.

You cannot set “the classifier of a bundle”, as a bundle cannot have a classifier.
If you want a classifier on all childs of the bundle, you have to iterate the bundle, for example like:

dependencies {
    libs.bundles.foo.get().forEach {
        implementation(it) {
            artifact {
                classifier = "bar"
            }
        }
    }
}

Thank you.
I envisaged this would have been the “behind the scenes” implementation of setting a classifier on a bundle. Thanks very much for your help.

Feel free to open a feature request or pull request, maybe the Gradle folks like it. :man_shrugging:
But actually, in most situations it is anyway better to use a component metadata rule to create proper variants you can then properly depend on instead of using classifiers. :slight_smile: