简体   繁体   中英

jlink: package kotlin.* in both merged module and kotlin.stdlib

Building a Kotlin JavaFX app via gradle (7.5.1), and trying to get packaging/installing with jlink/jpackage working. The application has a module-info.java :

module com.foo.bar {
    requires javafx.controls;
    requires javafx.fxml;
    requires de.jensd.fx.glyphs.fontawesome;
    requires kotlin.stdlib;
    requires com.github.ajalt.clikt;
    requires com.google.gson;
    requires java.sql;

    opens com.foo.bar to javafx.fxml, com.google.gson;
    exports com.foo.bar;
}

gradle jlink runs without any issues, but on executing the script, the following error happens:

Error occurred during initialization of boot layer
java.lang.LayerInstantiationException: Package kotlin.* in both module com.foo.merged.module and module kotlin.stdlib

where * is some library (it changes every time). The build.gradle is as follows:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.6.20'
    id 'org.openjfx.javafxplugin' version '0.0.13'
    id 'org.beryx.jlink' version '2.25.0'
    id 'application'
}

group 'com.foo'
version '1.0'

repositories {
    mavenCentral()
}

dependencies {
    implementation platform('org.jetbrains.kotlin:kotlin-bom')
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'

    implementation 'com.github.ajalt.clikt:clikt:3.5.0'
    implementation 'com.google.code.gson:gson:2.10'
    implementation 'de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2'
    implementation 'org.postgresql:postgresql:42.5.0'
    implementation 'org.xerial:sqlite-jdbc:3.39.3.0'

    testImplementation 'org.jetbrains.kotlin:kotlin-test'
    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
}

application {
    mainModule = 'com.foo.bar'
    mainClass = 'com.foo.bar.MainKt'
}

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

jlink {
    imageZip = project.file("${buildDir}/distributions/bar-${javafx.platform.classifier}.zip")
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'bar'
    }

    jpackage {
        outputDir = 'packages'
        installerType = 'dmg'
    }
}

When taking a look at the suggested merged modules ( gradle suggestMergedModuleInfo ), there is no mention of any kotlin libraries

> Task :suggestMergedModuleInfo
mergedModule {
    requires 'java.management';
    requires 'java.naming';
    requires 'java.logging';
    requires 'java.security.sasl';
    requires 'java.sql';
    requires 'java.xml';
    requires 'java.desktop';
    requires 'java.transaction.xa';
    requires 'java.security.jgss';
    provides 'java.sql.Driver' with 'org.postgresql.Driver',
                                'org.sqlite.JDBC';
}

Edit: so the actual merged module does not seem to have any references to any kotlin libraries:

open module com.foo.merged.module {
    exports com.github.ajalt.clikt.completion;
    exports com.github.ajalt.clikt.core;
    exports com.github.ajalt.clikt.internal;
    exports com.github.ajalt.clikt.mpp;
    exports com.github.ajalt.clikt.output;
    exports com.github.ajalt.clikt.parameters.arguments;
    exports com.github.ajalt.clikt.parameters.groups;
    exports com.github.ajalt.clikt.parameters.internal;
    exports com.github.ajalt.clikt.parameters.options;
    exports com.github.ajalt.clikt.parameters.types;
    exports com.github.ajalt.clikt.parsers;
    exports com.github.ajalt.clikt.sources;
    exports org.checkerframework.checker.compilermsgs.qual;
    exports org.checkerframework.checker.fenum.qual;
    exports org.checkerframework.checker.formatter;
    exports org.checkerframework.checker.formatter.qual;
    exports org.checkerframework.checker.guieffect.qual;
    exports org.checkerframework.checker.i18n.qual;
    exports org.checkerframework.checker.i18nformatter;
    exports org.checkerframework.checker.i18nformatter.qual;
    exports org.checkerframework.checker.index.qual;
    exports org.checkerframework.checker.initialization.qual;
    exports org.checkerframework.checker.interning.qual;
    exports org.checkerframework.checker.lock.qual;
    exports org.checkerframework.checker.nullness;
    exports org.checkerframework.checker.nullness.qual;
    exports org.checkerframework.checker.optional.qual;
    exports org.checkerframework.checker.propkey.qual;
    exports org.checkerframework.checker.regex;
    exports org.checkerframework.checker.regex.qual;
    exports org.checkerframework.checker.signature.qual;
    exports org.checkerframework.checker.signedness;
    exports org.checkerframework.checker.signedness.qual;
    exports org.checkerframework.checker.tainting.qual;
    exports org.checkerframework.checker.units;
    exports org.checkerframework.checker.units.qual;
    exports org.checkerframework.common.aliasing.qual;
    exports org.checkerframework.common.reflection.qual;
    exports org.checkerframework.common.returnsreceiver.qual;
    exports org.checkerframework.common.subtyping.qual;
    exports org.checkerframework.common.util.report.qual;
    exports org.checkerframework.common.value.qual;
    exports org.checkerframework.dataflow.qual;
    exports org.checkerframework.framework.qual;
    exports org.checkerframework.framework.util;
    exports org.intellij.lang.annotations;
    exports org.jetbrains.annotations;
    exports org.postgresql;
    exports org.postgresql.copy;
    exports org.postgresql.core;
    exports org.postgresql.core.v3;
    exports org.postgresql.core.v3.adaptivefetch;
    exports org.postgresql.core.v3.replication;
    exports org.postgresql.ds;
    exports org.postgresql.ds.common;
    exports org.postgresql.fastpath;
    exports org.postgresql.geometric;
    exports org.postgresql.gss;
    exports org.postgresql.hostchooser;
    exports org.postgresql.jdbc;
    exports org.postgresql.jdbc2;
    exports org.postgresql.jdbc2.optional;
    exports org.postgresql.jdbc3;
    exports org.postgresql.jre7.sasl;
    exports org.postgresql.largeobject;
    exports org.postgresql.osgi;
    exports org.postgresql.plugin;
    exports org.postgresql.replication;
    exports org.postgresql.replication.fluent;
    exports org.postgresql.replication.fluent.logical;
    exports org.postgresql.replication.fluent.physical;
    exports org.postgresql.shaded.com.ongres.saslprep;
    exports org.postgresql.shaded.com.ongres.scram.client;
    exports org.postgresql.shaded.com.ongres.scram.common;
    exports org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64;
    exports org.postgresql.shaded.com.ongres.scram.common.bouncycastle.pbkdf2;
    exports org.postgresql.shaded.com.ongres.scram.common.exception;
    exports org.postgresql.shaded.com.ongres.scram.common.gssapi;
    exports org.postgresql.shaded.com.ongres.scram.common.message;
    exports org.postgresql.shaded.com.ongres.scram.common.stringprep;
    exports org.postgresql.shaded.com.ongres.scram.common.util;
    exports org.postgresql.shaded.com.ongres.stringprep;
    exports org.postgresql.ssl;
    exports org.postgresql.ssl.jdbc4;
    exports org.postgresql.sspi;
    exports org.postgresql.translation;
    exports org.postgresql.util;
    exports org.postgresql.util.internal;
    exports org.postgresql.xa;
    exports org.postgresql.xml;
    exports org.sqlite;
    exports org.sqlite.core;
    exports org.sqlite.date;
    exports org.sqlite.javax;
    exports org.sqlite.jdbc3;
    exports org.sqlite.jdbc4;
    exports org.sqlite.util;
    requires java.management;
    requires java.naming;
    requires java.logging;
    requires java.security.sasl;
    requires java.sql;
    requires java.xml;
    requires java.desktop;
    requires java.transaction.xa;
    requires java.security.jgss;
    provides java.sql.Driver with org.postgresql.Driver, org.sqlite.JDBC;
}

Not sure why this is needed, but specifying forceMerge 'kotlin' in the jlink block fixes the issue. Seehttps://badass-jlink-plugin.beryx.org/releases/latest/#_methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM