Want year 2023 example code of minimal Kotlin+JavaFX+Gradle that works!

Answered

Platform details: Ubuntu 18.04/ 64 bit/ 16 GB Memory

When starting a project in IntelliJ, I choose Kotlin and Gradle and JavaFX and then select all checkboxes for JavaFX presented.

When running the (demo) app for first time with no modifications, it will not run and I haven't been able to make it run. 

Really, I shouldn't have to struggle with the app right out of the box.

Can someone please show me a working app properly configured so it will run with the above selections so I may get to ‘real’ programming development?

0
4 comments

Ethan Yin     – When I removed the module-info.java file from the app the IDE complained, so that didn't work. 

I did find (from seeing the link you recommended) that the app would run if I use the recommendation below of: You can still run the Gradle project by going to the Gradle window and double-clicking on Tasks | Application | run. However, when I terminate the app it still showed that an error occurred in the build! This may be a problem when it comes to distribution?! I prefer an environment clear of problems the IDE should be handling.

Additionally, this part of the description in the link you recommended: If your application is written solely in Kotlin (IT IS NOT- in my mind since I am also using JavaFX) then I would suggest removing the module-info.java file. You'll just have to make sure JavaFX is loaded from the module-path via --module-path and --add-modules, is unclear to me. I need to know step by step, how I go about ensuring JavaFX is loaded from the module-path via --module-path and --add-modules. Can you explain this please?

Also, this part of the description in the link you recommended: But if your code is a mix of Java and Kotlin, then I believe the recommendation is to put the source files of both languages in the same source directory (src/main/java). In that case, you might be able to have a module descriptor, but I don't know how well Kotlin and JPMS work together, is also unclear to me. Exactly how would the Project Structure look like when sources of both languages are in the same source directory? Can you show me what this would look like? This is not at all reassuring when one is depending on the IDE to ensure these things don't cause problems down the road. If this the is the best that can be had at the moment I will be patient and wait for fixes, but if there is a more solid approach please explain it to me.

Does all this hassle still occur when using Java 8 (since it has the JavaFX inside it)?

I would still much prefer for someone to hand me a solid working example (including problem work-arounds) instead of a link that will most likely just prolong wrestling with the IDE instead of letting me work on the development of my app. Can you please show me a solid working example to follow once and for all?

 

 

The two paragraphs shown below for reference, are from the link you recommended :

No, a module descriptor is not necessary. If your application is written solely in Kotlin then I would suggest removing the module-info.java file. You'll just have to make sure JavaFX is loaded from the module-path via --module-path and --add-modules or by using a run-time image that includes JavaFX. But if your code is a mix of Java and Kotlin, then I believe the recommendation is to put the source files of both languages in the same source directory (src/main/java). In that case, you might be able to have a module descriptor, but I don't know how well Kotlin and JPMS work together.

– Slaw

Jul 1, 2022 at 14:55

If you use Maven instead of Gradle in the wizard it works (can click on the green arrow in the gutter for the Application class and it will run). But the same thing will fail if you choose Gradle, with the error you show. You can still run the Gradle project by going to the Gradle window and double-clicking on Tasks | Application | run. I think by default, intellij is too dumb to be able to correctly configure the run configuration for the JavaFX application in the IDE with a default new JavaFX project Gradle Kotlin build. File an enhancement request with IntelliJ about it if you want.

– jewelsea

Jul 1, 2022 at 23:13

0

It seems like a known issue in the IDE: https://youtrack.jetbrains.com/issue/IDEA-274543/JavaFX-project-wizard-doesnt-work

The only workaround I know is as you mentioned, running it by gradle cli.

0

Please sign in to leave a comment.