0

I'm trying to develop a Gradle project which involves JavaFX.

Specs: Linux Mint 18.3, Java 11, Eclipse 2019-06, JavaFX: either 13 or 11...

A couple of useful answers to questions have helped me over the past hours: this one tells me (with useful clonable example) how to configure things, at least using a Java file to hold my project's main class (in fact I ultimately want to write all my code in Groovy ideally), in order to overcome the error "JavaFX runtime components are missing, and are required to run this application".

But Eclipse doesn't like it when you add the final step: the file module-info.java. At this point I have to confess I know nothing whatsoever about Eclipse "modules": only that this unknown aspect of the IDE has occasionally caused me frustrating headaches in the past. Probably time to read up on it now.

I should also clarify that at this point the Gradle tasks build and installdist (or assemble) work fine at the CLI. I am only concerned about getting rid of these horrid Eclipse white-cross-in-red-box error marks:

  1. in module-info.java: "javafx.controls cannot be resolved to a module"
  2. in Main.java: all the JavaFX classes have this next to them "Application [etc.] cannot be resolved to a type", and all the imports have "The type javafx.scene.Scene [etc.] is not accessible"

This answer says to download the JavaFX-JDK and then add various .jars from it to your project's module path. I did that: the horrid errors all disappeared!

Next time I did a Gradle - Refresh they all came back. I checked module path: all these .jar files had been removed. How can I stop the Gradle-Eclipse functionality messing with my configured module path?

edit

re the comment by Slaw: yes, already using

id 'org.openjfx.javafxplugin' version '0.0.8'

... my build.gradle javafx block looks like this:

javafx {
    version = "13"
    modules = [ 'javafx.controls', 'javafx.fxml' ] 
}

(NB I have now tried experimenting by adding 'javafx.graphics' and 'javafx.base' to the above.) The issue is that Gradle - Refresh nevertheless causes the above "disappearing .jars" phenomenon.

I tried adding this to my plugins block:

id 'org.javamodularity.moduleplugin' version '1.6.0' apply true/false // NB tried both

... no go: Gradle - Refresh leads to an incomprehensible (to me) error:

An exception occurred applying plugin request [id: 'org.openjfx.javafxplugin', version: '0.0.8']
> Failed to apply plugin [id 'org.openjfx.javafxplugin']
   > Could not create task ':configJavafxRun'.
      > Could not create task of type 'ExecTask'.
         > Could not generate a decorated class for class org.openjfx.gradle.tasks.ExecTask.
            > org/javamodularity/moduleplugin/tasks/ModuleOptions
mike rodent
  • 14,126
  • 11
  • 103
  • 157
  • I am sorry, I don't use Eclipse. Is it a requirement to use it ? If not, you can use Intellij IDEA community instead. You will probably not have problems to import gradle projects with it – Flpe Mar 05 '20 at 22:06
  • 2
    Note that module-info files are not IDE-specific; they are a Java language feature added in version 9. Since you're using Gradle you'll want to add the JavaFX dependencies via Gradle itself. This is made easier by applying the [javafx-gradle-plugin](https://github.com/openjfx/javafx-gradle-plugin). IIRC, that plugin also applies the [gradle-modules-plugin](https://github.com/java9-modularity/gradle-modules-plugin). – Slaw Mar 05 '20 at 23:54
  • If you're not **intentionally** using Java Platform Module System, delete the `module-info.java` file. – nitind Mar 05 '20 at 23:56
  • Thanks all. 1) Intellij - I've never looked into it, but always assumed its "Community" (non-paying) edition will turn out to be too hobbled. 2) yes, I have to use module-info in order to get the jlink functionality to work. 3) already use the JavaFX Gradle plugin: now looking into the Gradle module plugin, which I've never heard of... – mike rodent Mar 06 '20 at 07:37
  • @Flpe I just downloaded and installed Intellij CE and confirm that your solution just works, simply, with no horrid spurious error marks, etc. – mike rodent Mar 06 '20 at 08:37
  • I've not used Eclipse in a long time, so I don't know why it isn't synchronizing with Gradle properly. But IntelliJ has great integration with Gradle (and Maven) in my experience. – Slaw Mar 06 '20 at 09:37

0 Answers0