This is my first javafx and gradle application. First I created a gradle project in IntelliJ and then I added JavaFX dependencies referring this tutorial. My gradle file looks like this:
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
plugins {
id 'application'
}
group 'com.skb'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
def javaFXPlatform = getJavaFXPlatform()
def javaFXVersion = "15.0.1"
dependencies {
// you need a dependency for each of the JavaFX modules you're going to use
implementation "org.openjfx:javafx-base:${javaFXVersion}:${javaFXPlatform}"
implementation "org.openjfx:javafx-controls:${javaFXVersion}:${javaFXPlatform}"
implementation "org.openjfx:javafx-graphics:${javaFXVersion}:${javaFXPlatform}"
}
application {
//Java Module System module name
mainModule.set('com.skb')
//Your JavaFX application class
mainClass.set('com.skb.EditorApp')
}
java {
// this enables Java Modularity in Gradle (version 6.7 and above)
modularity.inferModulePath.set(true)
}
// Based on this StackOverflow answer: https://stackoverflow.com/a/65209664/653519
private static String getJavaFXPlatform() {
def currentOS = DefaultNativePlatform.currentOperatingSystem
if (currentOS.isWindows()) {
return 'win'
} else if (currentOS.isLinux()) {
return 'linux'
} else if (currentOS.isMacOsX()) {
return 'mac'
}
return null
}
My module_info.java lloks like this:
module com.skb {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
requires java.base;
//requires org.fxmisc.richtext;
//requires org.json;
opens com.skb;
}
EditorApp class contains just some biolerplate code:
package com.skb;
import javafx.application.Application;
import javafx.stage.Stage;
public class EditorApp extends Application {
@Override
public void start(Stage primaryStage) {
System.out.println("Running...");
}
public static void main(String[] args) {
launch(args);
}
}
Project structure is like this:
I am using IntelliJ 2021.1 Community Edition.
Please help me out. I have already searched a lot on this error, and got nothing that solved the error.