Please check <https://github.com/edvin/tornadofx/p...
# tornadofx
a
c
So basically you suggest to stop using module system. That's not a solution it's a regressive work-around 😞
a
I am not suggesting to stop using module system. I have just suggested a solution without using JPMS 🙂
c
I don't see difference 😄
nvm. my problem is not even with tornadofx, I can't seem to make plain javafx work too. Something with gradle setup probably 😐
a
JDK 9 is not just about module-path. You can still use class path and everything in your application should work fine.
Gradle + JDK9 + JavaFX?
c
Gradle + JDK10 + JavaFX. It works in IntelliJ both build and run, but I can't compile it with gradle.
a
Can you link me the project or just
build.gradle
?
Oh, wait. What exception do you get? You need gradle 4.8+ to run 10.
c
gradle is 4.10 JDK is 10.0.2 from Oracle exception is
e: Module javafx.controls cannot be found in the module graph
And this is my build file:
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
	`java-library`
	kotlin("jvm")
	kotlin("plugin.spring")
	id("org.springframework.boot")
	id("io.spring.dependency-management") version "1.0.6.RELEASE"
}

group = "com.example"
version = "1.0-SNAPSHOT"

java {
	sourceCompatibility = JavaVersion.VERSION_1_10
	targetCompatibility = JavaVersion.VERSION_1_10
}

tasks.withType<Wrapper> {
	gradleVersion = "4.10"
	distributionType = Wrapper.DistributionType.ALL
}

tasks.withType<KotlinCompile> {
	kotlinOptions {
		jvmTarget = JavaVersion.VERSION_1_8.toString()
		freeCompilerArgs = listOf("-Xjsr305=strict")
	}
}

repositories {
	jcenter()
	maven(url = "<https://repo.spring.io/libs-milestone>")
}

dependencies {
	listOf(
		kotlin("stdlib-jdk8"),
		kotlin("reflect"),
		springBoot("starter")
	).forEach { implementation(it) }
}

fun springBoot(module: String, version: String = "") = "org.springframework.boot:spring-boot-$module:$version"
The module:
Copy code
module com.example {
	requires kotlin.stdlib;
	requires kotlin.stdlib.jdk8;
	requires spring.core;
	requires spring.boot.autoconfigure;
	requires spring.boot;
	requires spring.context;
	requires javafx.controls;

	opens com.example to spring.core;

	exports com.example;
}
a
This isn't a plain JavaFX application 😛
c
Now it is, poblem is the same 😛
Fixed it! FYI, adding this to build file helped:
Copy code
val compileJava: JavaCompile by tasks
compileJava.apply {
	dependsOn("compileKotlin")
	doFirst {
		options.compilerArgs = listOf(
			"--module-path", classpath.asPath
		)
		classpath = files()
	}
}
a
OK, makes sense. Do you still need
requires kotlin.stdlib;
in
module-info.java
?
The project I was trying runs without it - https://github.com/abhinayagarwal/KotlinJPMS
c
Interesting, you're right, I could remove all
requires
statements except javafx and tornadofx and the app still works. I wonder why...
Actually it only works from command line now, IntelliJ complains about missing modules =D
Symbol is declared in module 'spring.boot.autoconfigure' which current module does not depend on
a
I found the issue with kotlin-stdlib. There is no
module-info.class
in the jar. I am sure your other dependencies have the same issue.
c
Same happens for stdlib too
a
If there is no module-info.class. Everything falls under UNNAMED module by default.
c
but if I declare everything correctly, everything works 🙂
If I don't declare module-info properly, then it only works from gradle but not from intellij
a
Command run by gradle:
Copy code
/usr/lib/jvm/java-10-oracle/bin/java -Dfile.encoding=UTF-8 -Duser.language=en -Duser.variant -cp KotlinJPMS/build/classes/java/main:KotlinJPMS/build/classes/kotlin/main:KotlinJPMS/build/resources/main:.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.61/5bc44acc4b3f0d19166ae3e50454b41e8ff29335/kotlin-stdlib-1.2.61.jar:.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.61/772de03e12d932f489e41aef997d26c20a4ebee6/kotlin-stdlib-common-1.2.61.jar:.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar xyz.abhinay.Main
Command run by IntelliJ:
Copy code
/usr/lib/jvm/java-10-oracle/bin/java -javaagent:.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-1/181.5540.7/lib/idea_rt.jar=32799:.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-1/181.5540.7/bin -Dfile.encoding=UTF-8 -p Documents/git/random/KotlinJPMS/out/production/classes:.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.61/5bc44acc4b3f0d19166ae3e50454b41e8ff29335/kotlin-stdlib-1.2.61.jar:.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.61/772de03e12d932f489e41aef997d26c20a4ebee6/kotlin-stdlib-common-1.2.61.jar:.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar -m xyz.abhinay/xyz.abhinay.MainKt
The important difference is gradle uses
-cp
referring to classpath where as Intellij uses
-p
referring to module-path.
Got it. We need to tell the run command to use modules as well:
Copy code
run {
    doFirst {
        jvmArgs = [
            '--module-path', classpath.asPath,
            '--module', mainClassName 
        ]
        classpath = files()
    }
}
Updated my sample 🙂
a
@abhinay is this what you have to do for using openjfx?
a
@amanda.hinchman-dominguez Yes
JavaFX modules need to be on the module path
a
yeah, I added them!
a
Does it work for you now?
a
It does not 😞
I’ve added the javafx.base as well, no difference
I read somewhere that you have to add
modules-info.java
to your projects now? I don’t know if it’s true. I don’t have multiple modules so
a
modules-info.java
is not mandatory
a
so I was watching this video -

https://www.youtube.com/watch?v=WtOgoomDewo

this mans says you gotta, I’ll try it… but what else could I have left out? I did the global javafx/lib as a global and added it to the module
wait lol nm
I don’t have to
those are for extras. I’ve already configured it in the run configs
hmmm… I wonder if it’s the way I imported the lib>
@abhinay
a
You need to add it to libraries, I guess.
a
yes, that is added as well. Turns out, I have to add the lib path to the module path! That’s what got me. It’s working now!
👍 1