Gradle JavaFX Jlink:应用程序模块路径上的重复模块

问题描述 投票:0回答:2

我有一个使用 gradle 的项目,一切都构建并完美运行,但我在打包应用程序时遇到问题。我在 WSL 上工作,希望同时拥有 Linux 和 Windows 可执行文件,但开始拥有一个就可以了,只要它能工作并且我可以理解如何在其他操作系统上复制它,我并不真正关心。

到目前为止,我已经在互联网上阅读了很多东西,并尝试使用这个插件来打包我的应用程序。但是当我使用

gradle jlink
时,我会收到关于重复模块问题的警告,如下所示。我尝试了很多方法,但在网上找不到任何有效的方法或类似的问题。您是否知道由于我的经验不足而我可能会忽略什么?

提前谢谢您!

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

这是我的 gradle.build 文件:


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']
    }
}

还有我的模块信息文件:

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;
}
java gradle javafx
2个回答
1
投票

我遇到了同样的问题,我发现文件夹 build/jlinkbase/jlinkjars 包含提到的两个平台的模块 - mac(我用来开发)和 win。

阅读后https://github.com/openjfx/javafx-gradle-plugin/issues/65我只需要识别“污染”库并应用修复程序,其中提到:

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

0
投票

罗伯特·克莱因施马格的回答确实对我有用。我不知道为什么。也许我没有正确地将其翻译为 kotlin dsl。

对我有用的是以下内容:

var os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
val discriminator = when {
    os.isLinux -> "linux"
    os.isMacOsX -> "mac"
    os.isWindows -> "win"
    else -> "(${os.name})"
}

tasks.named("prepareMergedJarsDir") {
    doLast {
        delete(fileTree("build/jlinkbase/jlinkjars").matching {
            include("*.jar")
            exclude("**/*$discriminator.jar")
        })
    }
}

所以删除除当前平台的jar之外的所有jar。

© www.soinside.com 2019 - 2024. All rights reserved.