Search code examples
javagradlejavafx

Gradle JavaFX Jlink : duplicate module on application module path


I have a project working with gradle and everything build and run perfectly but I have issues packaging my application. I work on WSL and would like to have both linux and windows executables but to begin having one is okay I don't really care as long as it works and I can understand how to replicate it on the other OS.

So far, I have read a lot of things on the internet and tried to use this plugin in order to package my application. But when I use gradle jlink, I am warned about a duplicate module issue as you can see below. I have tried many things but cannot find anythign which works or a similar problem on the web. Would you have any clue on what I may be overlooking because of my inexperience?

Thank you in advance !

Starting a Gradle Daemon, 31 busy and 1 incompatible and 12 stopped Daemons could not be reused, use --status for details

> Configure project :
Project : => 'CharacterCreator' Java module

> Task :createMergedModule
error: duplicate module on application module path
  module in javafx.base
error: duplicate module on application module path
  module in javafx.controls
2 errors

> Task :createMergedModule FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':createMergedModule'.
> Process 'command '/opt/graalvm-svm-java11-linux-gluon-22.1.0.1-Final/bin/javac'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 42m 15s
5 actionable tasks: 3 executed, 2 up-to-date

Here is my gradle.build file :


plugins {
  id 'java'
  id 'org.openjfx.javafxplugin' version '0.0.13'
  id 'org.beryx.jlink' version '2.16.2'
}

repositories {
    mavenCentral()
    mavenLocal()
}

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

dependencies {
    implementation "org.aerofx:aerofx:0.2"
    implementation "pdfbox:pdfbox:0.7.3"
    implementation "org.javatuples:javatuples:1.2"
    implementation "org.controlsfx:controlsfx:11.0.3"
    implementation "org.mariadb.jdbc:mariadb-java-client:2.1.2"
    implementation "io.gitlab.vincent-lambert:miscellaneousWidgets:1.7"
    implementation "org.apache.httpcomponents:httpclient:4.5.13"
    implementation "org.apache.httpcomponents:httpmime:4.3.1"
}

application {
    mainModule = 'CharacterCreator'
    mainClass = 'CharacterCreator.Menu.App'
}

tasks.withType(JavaCompile) {
    options.compilerArgs << '-Xlint:unchecked'
    options.deprecation = true
}

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher{
        name = 'hello'
        jvmArgs = ['-Dlog4j.configurationFile=./log4j2.xml']
    }
}

And my module-info file :

module CharacterCreator {
    requires aerofx;
    requires javafx.fxml;
    requires pdfbox;
    requires javatuples;
    requires java.sql;
    requires javafx.base;
    requires javafx.graphics;
    requires javafx.controls;
    requires org.controlsfx.controls;
    requires mariadb.java.client;
    requires miscellaneousWidgets;
    requires java.desktop;
    requires java.net.http;
    requires httpmime;
    
    opens CharacterCreator.Creator to javafx.fxml;
    exports CharacterCreator.Creator;
    opens CharacterCreator.Edits to javafx.fxml;
    exports CharacterCreator.Edits;
    opens CharacterCreator.Menu to javafx.fxml;
    exports CharacterCreator.Menu;
    opens CharacterCreator.Misc to javafx.fxml;
    exports CharacterCreator.Misc;
    opens CharacterCreator.Races to javafx.fxml;
    exports CharacterCreator.Races;
    opens CharacterCreator.Relations to javafx.fxml;
    exports CharacterCreator.Relations;
    opens CharacterCreator.Visus to javafx.fxml;
    exports CharacterCreator.Visus;
}

Solution

  • I had the same problem, and I found out, that the folder build/jlinkbase/jlinkjars contained mentioned modules for both platform - mac (which I use to develop) and win.

    after reading https://github.com/openjfx/javafx-gradle-plugin/issues/65 I just needed to identify the "polluting" library and applied the fix, which was mentioned:

    implementation (....) { exclude group:org.openjfx }