Transitive dependencies with Gradle & OpenJFX

Viewed 55

I am in the process of setting up JavaFX-based project with Gradle 7.3. The project has the following structure:

project/
├─ boot/
├─ gui/
├─ other_module1/
├─ other_moduleN/

All JavaFX related code belongs into the GUI module, while boot defines the entry point.


The gui/build.gradle.kts for the module GUI uses the OpenJFX plugin:

plugins {
    `java-library`
    id("org.openjfx.javafxplugin") version "0.0.10"
}

// ...

javafx {
    version = "17"
    modules("javafx.controls", "javafx.fxml")
}

whereas the boot package only imports GUI:

plugins {
    application
}

dependencies {
    implementation(project(":gui"))
    implementation(project(":network"))
}

application {
    mainClass.set("project.boot.Boot")
}

tasks.withType<Jar> {
    manifest {
        attributes["Main-Class"] = "project.boot.Boot"
    }
}

Using this setup, my project wont compile and crashes while working on boot:

error: cannot access Application
        Game.execute(args);
            ^
  class file for javafx.application.Application not found

This can be fixed by also applying the OpenJFX Plugin - the same way as seen above - to boot (boot/build.gradle.kts).


QUESTION: How can I apply JavaFX transitively, so that it remains an implementation detail within the GUI module?

As I am new to Gradle and Java, I am probably missing something small yet crucial.

Also, I tried to read the docs, but the OpenJFX Plugin docs are quite outdated and often do not work as they are.

0 Answers
Related