0

I am using following build.gradle.kts for JavaFX app

plugins {
    kotlin("jvm") version "1.4.30"
    id("application")
    id("org.openjfx.javafxplugin") version "0.0.9"
}

repositories {
    mavenCentral()
}

javafx {
    version = "11"
    modules("javafx.controls", "javafx.fxml")
    sdk = System.getenv("JAVAFX")
    if (sdk == null || sdk2.isBlank()) {
       throw InvalidUserDataException("JAVAFX environment variable is not set. JAVAFX = $sdk")

    }
    application {
        mainClass.set("example.Main")
        applicationName = "Main"
        applicationDefaultJvmArgs = listOf(
            "--module-path=${sdk}${File.separator}lib",
            "--add-modules=javafx.controls,javafx.fxml" )

        println("applicationDefaultJvmArgs:$applicationDefaultJvmArgs")
    }
}

dependencies {
    implementation(kotlin("stdlib"))
}

I have set environmental variable in .bashrc like below

export JAVAFX=$HOME/path/to/JavaFX/SDK

when I execute echo $JAVAFX I get the JavaFX SDK path but still I am getting null in build.gradle.kts

Tried restarting IntelliJ idea too, still the same.

2
  • 1
    You may need to also kill any Java processes that Gradle has started in the background as well. Depending on your system, open up task manager and kill and lingering Java process. Commented Feb 11, 2021 at 16:09
  • @FranciscoMateo It seems you are right, now it works fine. You may write an answer so I could accept. Commented Feb 12, 2021 at 3:31

1 Answer 1

1

Out-of-the-box, Gradle will spawn a Java process in the background. Typically this is the Gradle Daemon, but there may be more.

So to ensure new environment variables are seen, it's best to kill any Java process that are running in the background. Depending on your system, open up task manager and kill and lingering Java process.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.