IntelliJ - JavaFX and JavaDoc: Two versions of module

Viewed 682

I got a bit of a struggle setting up IntelliJ for a JavaFX project. I set it up using File > Project Structure > Libraries > Add new library > From Maven searching for org.openjfx:javafx-fxml:11.0.2. So it was found and I deliberately checked Download JavaDocs since this would be useful.

However, when I tried to start the project, I got the following error:

java.lang.module.FindException: Two versions of module javafx.graphics found in lib (javafx-graphics-11.0.2-linux.jar and javafx-graphics-11.0.2-javadoc.jar)

Apparently the compiler mistoke javadoc for another version...

When I then removed the *javadoc.jar files downloaded for JavaFX the program started just fine. As you can imagine, I would like to keep the possibility to read JavaDoc directly in my IDE.

Any ideas how to fix that?

Edit: Here is a sample repo at Github: leun4m/javafx-demo@2a7a03a

Run Configuration:

--module-path lib --add-modules javafx.controls,javafx.fxml
2 Answers

I managed to make to compile, run and get docs in your project by doing next:

  1. Adding a pom.xml to the root:

4.0.0

<groupId>org.example</groupId>
<artifactId>java-fx-pom</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <java.version>1.13</java.version>
    <maven.compiler.source>13</maven.compiler.source>
    <maven.compiler.target>13</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11.0.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.3</version>
            <configuration>
                <mainClass>Main</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>
  1. building with mvn clean install
  2. running with javafx:run -f pom.xml
  3. to get better docs you need to go "inside" any javafx method, you can do that by putting cursor and pressing Ctrl+B, and click on "Download Sources"
  4. Finally I've created a PR to your test repository. I've intentionally pushed some idea files, that should reduce amount of errors you get.

In case you're in the special situation where you can't use any build tools like Maven or Gradle, someone recently showed me a workaround:

  1. Go to Project Structure > Global Libraries
  2. Add the library
    • make sure you uncheck Download to or select a different directory than lib/
    • check sources and or javadoc (depending on your needs)

This way the project can be run like before, but IntelliJ can show you the documentation or even the source code of the imported library without any conflicts regarding building and executing the application.

IntelliJ will now list as a problem, that the library in the project itself is no longer needed (since it's in fact duplicated now). However, this is not a problem since the lib directory will still be used for executing the project via the run configuration.

Related