We will in few steps how we can work on javaFX within a gradle project in the new intellij build 2019.2 which may apply other builds too.

Creating the project

In intellij we go to File > New > Project and we select Gradle then on the right menu we select Java.

Click next then in GroupId put the package name could be something like com.domain.app (at least one dot should be included) and the ArtifactId could be your program name and put the version then click next.

Select the project name and location then click finish.

Adding JavaFX support

Go to project tab and then build.gradle under the project name (Make sure you are in the project view from the dropdown menu)

Your default build.gradle will look like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
plugins {
    id 'java'
}

version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

In plugins and under id ‘java’ add:

1
id 'org.openjfx.javafxplugin' version '0.0.8'

And also at the bottom add the following:

1
2
3
4
5
javafx {
    version = '12'
    modules = [ 'javafx.controls', 'javafx.fxml' ]
    configuration = 'compileOnly'
}

Make sure that the version matches your build JDK version and also include more modules if you want but by default some modules like javafx.base and javafx.graphics are javafx.controls and javafx.fxml.

Now, click the gradle tab on the right and click refresh button on its upper menu.

Adding UTF-8 support to the gradle and JavaFX project

This is necessary if you want to deal with some non English texts like, Arabic, Kurdish and so on.

You will need to add the following to the bottom of the build.gradle file:

1
2
3
4
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

Now, click the gradle tab on the right and click refresh button on its upper menu.

That’s it, don’t forget to comment if you had any issues with these steps.