10

When I try to run my entire project in NetBeans I get the following error log:

...
Task :run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> org.joor.ReflectException: java.lang.NoSuchFieldException: javaExecHandleBuilder

* 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 4s

I don't know what's going on, I specified the main class in build.gradle... Pls, help!

AtomX
  • 364
  • 2
  • 13
  • 6
    This is a known [issue](https://github.com/openjfx/javafx-gradle-plugin/issues/89). For now, use Gradle 6.5 or lower. – José Pereda Sep 21 '20 at 17:51
  • Ugh! What a pain... Anyway, thanks for the help... – AtomX Sep 21 '20 at 18:21
  • Btw, I'm getting warning: No module was provided for main class, assuming the current module. Prefer providing 'mainClassName' in the following format: '$moduleName/a.b.Main' – AtomX Sep 21 '20 at 18:22
  • What's that...? I was using Gradle 6.6.1, downgrade to 6.3 (Default one which came with NetBeans) – AtomX Sep 21 '20 at 18:23

2 Answers2

10

I found a solution to develop JavaFX project with Gradle version 6.6 or newer. You need to remove the javafx-gradle-plugin and use the JPMS support from Gradle itself. With removing the javafx-gradle-plugin, you need to maintain the JavaFX dependencies by yourself. Here an example of the build.gradle setup.

plugins {
    id 'application'
}

def currentOS = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem;
def platform
if (currentOS.isWindows()) {
     platform = 'win'
} else if (currentOS.isLinux()) {
     platform = 'linux'
} else if (currentOS.isMacOsX()) {
     platform = 'mac'
}

java {
    modularity.inferModulePath = true
}

dependencies {
    implementation "org.openjfx:javafx-base:15.0.1:${platform}"
    implementation "org.openjfx:javafx-controls:15.0.1:${platform}"
    implementation "org.openjfx:javafx-graphics:15.0.1:${platform}"
    implementation "org.openjfx:javafx-fxml:15.0.1:${platform}"
}

application {
    mainModule = 'com.your.module'
    mainClass = 'com.your.package.Main'
}

On your module-info.java file you need to declare the require JavaFX module.

module com.your.module {

    requires javafx.base;
    requires javafx.controls;
    requires javafx.graphics;
    requires javafx.fxml;

    opens com.your.package to javafx.fxml;

    exports com.your.package;

}
Sukma Wardana
  • 540
  • 8
  • 21
4

There now exists a fork of the JavaFX Gradle plugin that removes the modularity plugin. The developer of said plugin recommends only using it if you are using Java 16 and/or Gradle 7.

Buildscript:

plugins {
    id 'application'
    id 'com.dua3.javafxgradle7plugin' version '0.0.9'
}

application {
    mainModule = 'module.name'
    mainClass = 'class.name'
}

javafx {
    version = '16'
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

Your module descriptor doesn't need to be changed.


Plugin info:

Maow
  • 661
  • 5
  • 8