0

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:
enter image description here

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.

Sourav Kannantha B
  • 2,860
  • 1
  • 11
  • 35
  • Have you tried with the javafx plugin as stated by gluon tutorial? Take a look at this example: https://openjfx.io/openjfx-docs/#gradle BTW, although the tutorial is for version 0.0.9 and the latest version of javafx plugin is 0.0.10, should work fine. – bichoFlyer Jul 31 '21 at 23:52
  • Yes, I tried that too. Now I created a new non-gradle project and working with it anyway. – Sourav Kannantha B Aug 01 '21 at 09:56

0 Answers0