Run HelloWorld using Gradle

Similar to Maven, we can declare the required JavaFX modules in the build.gradle file. However, for Gradle we need to apply the JavaFX gradle plugin:


plugins {
  id 'application'
  id 'org.openjfx.javafxplugin' version '0.0.5'
}

Next, we add the required modules. For instance, if we only need the javafx.controls module, we will include:


javafx {
    version = "12"
    modules = [ 'javafx.controls' ]
}

Important: Note that transitive dependencies are automatically resolved (for instance, there is no need to add a dependency for the javafx.graphics module, since it is transitively resolved by the javafx.controls module). But if your application is using FXML, you will need to add the javafx.fxml module as well.

You can specify a distinct version of JavaFX. For example, if you want to stick to JavaFX 17.0.8:


javafx {
    version = "17.0.8"
    modules = [ 'javafx.controls' ]
}

Here is a build.gradle file which shows how to achieve this, taken from this sample.

Run the application (e.g. use HelloFX.java from the given sample) using:


./gradlew run

gradlew run
Note: Our recommendation for the minimum Gradle version against each JDK is as follows:
JDK version 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Gradle Version 5.0 5.4 6.0 6.3 6.7 7.0 7.3 7.5 7.6 8.3 8.5 8.8 8.10 N/A