Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a cross-platform build of JavaFX using Gradle

I'm working on a new project using Gradle and JavaFX. I have previously been able to create a cross-platform build using Maven, with the following pom dependencies:

<dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>13</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>13</version>
            <classifier>linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>13</version>
            <classifier>mac</classifier>
        </dependency>

How do i go about doing something similar with Gradle? I have tried the following, with no success. Is the classifier syntax incorrect?

compile group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2:win'
compile group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2:linux'
compile group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2:mac'

Any hints would be greatly appreciated!

like image 631
ole Avatar asked Sep 20 '25 04:09

ole


2 Answers

The solution turned out to be the following gradle build dependencies:

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'

This allows a javafx gradle build to be run on any OS.

like image 105
ole Avatar answered Sep 21 '25 19:09

ole


The syntax is indeed incorrect in Gradle. Documentation will show you the different supported syntax.

The two most common are the map style you used and the : separated notation.

So taking one of your dependency as an example, you need to use either:

  • compile group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2', classifier: 'win'
  • compile 'org.openjfx:javafx-graphics:11.0.2:win'

Note that you should also stop using the compile configuration and instead use implementation. See this explanation to understand more on this topic.

like image 38
Louis Jacomet Avatar answered Sep 21 '25 18:09

Louis Jacomet