Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I add JavaFX to a gradle build file using Kotlin DSL?

how do I add the javafx dependencies through gradle?

thufir@dur:~/NetBeansProjects/helloWorldJavaFX$ 
thufir@dur:~/NetBeansProjects/helloWorldJavaFX$ gradle clean

> Configure project :
e: /home/thufir/NetBeansProjects/helloWorldJavaFX/build.gradle.kts:13:7: Unresolved reference: openjfx

FAILURE: Build failed with an exception.

* Where:
Build file '/home/thufir/NetBeansProjects/helloWorldJavaFX/build.gradle.kts' line: 13

* What went wrong:
Script compilation error:

  Line 13:   org.openjfx.javafxplugin
                 ^ Unresolved reference: openjfx

1 error

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
thufir@dur:~/NetBeansProjects/helloWorldJavaFX$ 

the manual says:

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

my build file has:

plugins {
    // Apply the java plugin to add support for Java
    java

  org.openjfx.javafxplugin

    // Apply the application plugin to add support for building an application
    application
}

which is generating the above error.

like image 321
Thufir Avatar asked Jun 08 '19 21:06

Thufir


People also ask

What is Kotlin DSL plugin?

Gradle's Kotlin DSL provides an alternative syntax to the traditional Groovy DSL with an enhanced editing experience in supported IDEs, with superior content assist, refactoring, documentation, and more.

How do I update my kotlin gradle plugin?

Select Tools | Kotlin | Configure Kotlin Plugin Updates. In the Update channel list, select the Early Access Preview channel. Click Check again. The latest EAP build version appears.

What is the Kotlin Gradle plugin?

You can use the official Kotlin Gradle Plugin from JetBrains to compile your Kotlin code to target JVM, Android, and JS. Gradle has features you cannot get from other build tools: A highly-customizable dependency resolution engine, visual build inspection and debugging tools, and many work avoidance mechanisms.


1 Answers

in the plugins-section you have to put

id("org.openjfx.javafxplugin") version "0.0.8"

instead of just org.openjfx.javafxplugin.

After that you can put a javafx-section like

javafx {
    modules("javafx.controls", "javafx.fxml")
}

somewhere (I prefere to put it next to the dependency-section). Here you can put in any module you need.

For further configuration posibilities have a look JavaFX Gradle Plugin.

like image 179
mathze Avatar answered Sep 20 '22 21:09

mathze