beryx / badass-jlink-plugin

Create a custom runtime image of your modular application
https://badass-jlink-plugin.beryx.org
Apache License 2.0
379 stars 25 forks source link

Cannot derive uses clause from service loader invocation - Error: module not found: javafx.* requires javafx.* #84

Closed Tonne-TM closed 5 years ago

Tonne-TM commented 5 years ago

Hi, i get the following error when running gradle jlink (gradle run is working fine)

Cannot derive uses clause from service loader invocation in: org/apache/commons/compress/utils/ServiceLoaderIterator.<init>().
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:415: error: module not found: javafx.graphics
    requires javafx.graphics;
                   ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:421: error: module not found: javafx.base
    requires javafx.base;
                   ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:426: error: module not found: javafx.controls
    requires javafx.controls;

Here is my build.gradle. (I tried different solutions like defining mergedModule by hand like in Issue #64 but it could not resolve my problem. New errors popped up)

plugins {
    id 'java'
    id 'idea'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.jlink' version '2.15.1'
}

repositories {
    mavenCentral()
}

group 'de.tuchemnitz'
version '1.0-SNAPSHOT'

sourceCompatibility = 11

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

dependencies {
    compile('org.xerial:sqlite-jdbc:3.28.0')

    compile group: 'org.apache.poi', name: 'poi', version: '4.1.0'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.1.0'

    //tiny log
    compile group: 'org.tinylog', name: 'tinylog-api', version: '2.0.0'
    compile group: 'org.tinylog', name: 'tinylog-impl', version: '2.0.0'
    compile group: 'org.jdom', name: 'jdom2', version: '2.0.6'
    compile group: 'io.github.java-diff-utils', name: 'java-diff-utils', version: '2.2.0'
    compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.1'
    compile group: 'org.xmlunit', name: 'xmlunit-core', version: '2.6.3'
}

mainClassName = "$moduleName/<package>.excelimporter.MainFX"

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'hellofx'
    }
}

Hier die module-info.java:


module excelimporer {
    requires javafx.controls;
    requires javafx.fxml;

    requires org.tinylog.api;
    requires java.sql;
    requires jdom2;

    opens <package>.excelimporter to javafx.fxml;
    opens <package>.excelimporter.ui.dialogs to javafx.fxml;
    opens <package>.excelimporter.ui.controller to javafx.fxml;
    opens <package>.excelimporter.pojo.database to javafx.base;

    exports <package>.excelimporter;
}

Here are the suggesrMergedModuleInfo

Cannot derive uses clause from service loader invocation in: org/apache/commons/compress/utils/ServiceLoaderIterator.<init>().
mergedModule {
    requires 'javafx.graphics';
    requires 'java.logging';
    requires 'java.sql';
    requires 'java.xml';
    requires 'java.desktop';
    requires 'java.security.jgss';
    requires 'javafx.base';
    requires 'jdk.unsupported';
    requires 'java.xml.crypto';
    requires 'java.management';
    requires 'java.naming';
    requires 'javafx.controls';
    requires 'jdk.javadoc';
    provides 'java.sql.Driver' with 'org.sqlite.JDBC';
    provides 'org.tinylog.provider.LoggingProvider' with 'org.tinylog.core.TinylogLoggingProvider';
    provides 'org.tinylog.writers.Writer' with 'org.tinylog.writers.ConsoleWriter',
                                'org.tinylog.writers.FileWriter',
                                'org.tinylog.writers.JdbcWriter',
                                'org.tinylog.writers.LogcatWriter',
                                'org.tinylog.writers.RollingFileWriter',
                                'org.tinylog.writers.SharedFileWriter';
    provides 'org.tinylog.policies.Policy' with 'org.tinylog.policies.DailyPolicy',
                                'org.tinylog.policies.SizePolicy',
                                'org.tinylog.policies.StartupPolicy';
    provides 'org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface' with 'org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery';
    provides 'org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface' with 'org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath';
}
siordache commented 5 years ago

Put the following line:

addExtraDependencies("javafx")

in the jlink block.

Tonne-TM commented 5 years ago

I added it. Now something seems not functioning with tinylog and (still) apache poi.

Cannot derive uses clause from service loader invocation in: org/apache/commons/compress/utils/ServiceLoaderIterator.<init>().
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:430: error: the service implementation does not have a default constructor: ConsoleWriter
    provides org.tinylog.writers.Writer with org.tinylog.writers.ConsoleWriter,
                                                                ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:431: error: the service implementation does not have a default constructor: FileWriter
                                org.tinylog.writers.FileWriter,
                                                   ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:432: error: the service implementation does not have a default constructor: JdbcWriter
                                org.tinylog.writers.JdbcWriter,
                                                   ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:433: error: the service implementation does not have a default constructor: LogcatWriter
                                org.tinylog.writers.LogcatWriter,
                                                   ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:434: error: the service implementation does not have a default constructor: RollingFileWriter
                                org.tinylog.writers.RollingFileWriter,
                                                   ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:435: error: the service implementation does not have a default constructor: SharedFileWriter
                                org.tinylog.writers.SharedFileWriter;
                                                   ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:436: error: the service implementation does not have a default constructor: DailyPolicy
    provides org.tinylog.policies.Policy with org.tinylog.policies.DailyPolicy,
                                                                  ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:437: error: the service implementation does not have a default constructor: SizePolicy
                                org.tinylog.policies.SizePolicy,
                                                    ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:438: error: the service implementation does not have a default constructor: StartupPolicy
                                org.tinylog.policies.StartupPolicy;
                                                    ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:439: error: the service implementation does not have a default constructor: XBeansXQuery
    provides org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface with org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery;
                                                                                                                   ^
<project>\build\jlinkbase\tmpjars\<package>.merged.module\module-info.java:440: error: the service implementation does not have a default constructor: XBeansXPath
    provides org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface with org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath;
siordache commented 5 years ago

Put also this in the `jlink block:

mergedModule {
    requires 'javafx.graphics';
    requires 'java.logging';
    requires 'java.sql';
    requires 'java.xml';
    requires 'java.desktop';
    requires 'java.security.jgss';
    requires 'javafx.base';
    requires 'jdk.unsupported';
    requires 'java.xml.crypto';
    requires 'java.management';
    requires 'java.naming';
    requires 'javafx.controls';
    requires 'jdk.javadoc';
    provides 'java.sql.Driver' with 'org.sqlite.JDBC';
    provides 'org.tinylog.provider.LoggingProvider' with 'org.tinylog.core.TinylogLoggingProvider';
}
Tonne-TM commented 5 years ago

Thanks its working!

There are still some warnings but they don't seem to cause problems:


<project>\excel-import-modular\build\jlinkbase\tmpjars\org.apache.commons.collections4\module-info.java:2: warning: [module] module name component collections4 should avoid terminal digits
open module org.apache.commons.collections4 {
                              ^
1 warning
<project>\excel-import-modular\build\jlinkbase\tmpjars\commons.math3\module-info.java:2: warning: [module] module name component math3 should avoid terminal digits
open module commons.math3 {
                   ^
1 warning
<project>\excel-import-modular\build\jlinkbase\tmpjars\jdom2\module-info.java:2: warning: [module] module name component jdom2 should avoid terminal digits
open module jdom2 {
            ^
1 warning
<project>\excel-import-modular\build\jlinkbase\tmpjars\jsr305\module-info.java:2: warning: [module] module name component jsr305 should avoid terminal digits
open module jsr305 {
            ^
1 warning
nucleate commented 4 years ago

Hi, I've got the same issue before. Then I wrote addExtraDependencies function in my jlink. Now it builds but when I'm trying to run my app nothing happens. I tried to run module from console inside app/mods directory and got:

java.lang.LayerInstantiationException: Package images in both module zoomaio.main and module zoomaio.merged.module.

module-info.java:

open module zoomaio.main {
    requires java.sql;
    requires static lombok;
    requires javafx.fxml;
    requires javafx.web;
    requires org.controlsfx.controls;
    requires jdk.jsobject;
    requires okhttp3;
    requires org.json;
    requires org.jsoup;
    requires jdk.crypto.ec;
    requires webdrivermanager;
    requires selenium.api;
    requires selenium.chrome.driver;
    requires selenium.support;
    requires selenium.remote.driver;
    requires TrayNotification.a8bfa597eb;
    requires java.desktop;
}

build.gradle:


plugins {
    id 'application'
    id 'java'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.jlink' version '2.17.6'
}

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

configurations {
    broken { extendsFrom implementation }
}

dependencies {
    compile group: 'com.google.guava', name: 'guava', version: '29.0-jre'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
    compile group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.8.1'
    compile (group: 'org.controlsfx', name: 'controlsfx', version: '11.0.1') {
        exclude group: 'org.openjfx'
    }
    compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.30.1'
    compile group: 'org.json', name: 'json', version: '20190722'
    compile group: 'org.jsoup', name: 'jsoup', version: '1.13.1'
    compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.4.0'
    compileOnly 'org.projectlombok:lombok:1.18.10'

    compile 'com.github.PlusHaze:TrayNotification:a8bfa597eb'

    annotationProcessor 'org.projectlombok:lombok:1.18.10'
}

project.ext.buildDate = new Date()
project.version = "0.1"

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

mainClassName = 'com.itechartgroup.zoomproxy.ZoomProxyApplication'

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    addExtraDependencies("javafx")
    launcher {
        name = 'Zoom proxies'
        forceMerge "selenium"
    }
    jpackage {
        installerType = project.findProperty('installerType')
        // we will pass this from the command line (example: -PinstallerType=msi)
        imageOptions += ['--icon', 'src/main/resources/images/logo.ico']
        installerOptions += [
                '--win-per-user-install', '--win-dir-chooser',
                '--win-menu', '--win-shortcut'
        ]
    }
}

jpackage {
    doFirst {
        project.getProperty('installerType') // throws exception if its missing
    }
}
siordache commented 4 years ago

Directories containing resources are also handled as packages by the Java Module System. One of your dependencies has a resource directory named images, which conflicts with your own images directory.

One way to solve this problem is to rename your images directory to something else.

nucleate commented 4 years ago

Directories containing resources are also handled as packages by the Java Module System. One of your dependencies has a resource directory named images, which conflicts with your own images directory.

One way to solve this problem is to rename your images directory to something else.

Don't know about resources as packages handling. Everything is fine now. Thank you.