I'm trying to build a relatively simple JavaFX application using Gradle. However, I have no idea how to do it.
I'm relatively new to Gradle, and for simple (non-javafx) project I've successfully used the plugins java
and application
to build and package libraries and command-line applications.
However, I'm completely stuck when it comes to JavaFX. I've read this article, which suggests using the JavaFX
plugin, however I could only find the source code for this plugin, but no documentation on how to actually obtain it an use it (in the article they simply apply it from a remote URL, but that fails on my machine, says I'm not authorized...)
Any clues on how to do this properly?
To create a JavaFX application, you need to instantiate the Application class and implement its abstract method start(). In this method, we will write the code for the JavaFX Application.
Here's an example Gradle JavaFX build on GitHub. Note that according to Bintray, the latest version of the plugin is 8.1.1, so replace the '0.3.0' in the plugin URL with '8.1.1' if you want the latest.
Just to be clear, this is a very unusual way to distribute a Gradle plugin. Most are much easier to incorporate in a build!
Edit: up-to-date fork that works using "apply plugin" https://github.com/FibreFoX/javafx-gradle-plugin
Here is my example project with OpenJDK 12, JavaFX 12 and Gradle 5.4. It uses the JavaFX Gradle plugin.
I hope somebody finds the Github project useful. Feel free to clone it. It is licensed with the Unlicense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With