1

I am using gradle 7.3.1 in Intellij 2021.3 to build a JavaFX application. And I need external libraries dependency for the backend part.

This is the complete build.gradle script that is pre-built by the idea:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.10'
    id 'org.beryx.jlink' version '2.24.1'
}

group 'com.github.zukarusan'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

ext {
    junitVersion = '5.8.1'
}

sourceCompatibility = '11'
targetCompatibility = '11'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

application {
    mainModule = 'com.github.zukarusan.app'
    mainClass = 'com.github.zukarusan.app.MainApplication'
}

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

dependencies {
    implementation('org.controlsfx:controlsfx:11.1.0')
    implementation('com.dlsc.formsfx:formsfx-core:11.3.2') {
        exclude(group: 'org.openjfx')
    }
    implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
    implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')

    implementation('com.github.wendykierp:JTransforms:3.1') // THIS IS THE EXTERNAL LIBRARY I ADDED

    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}

test {
    useJUnitPlatform()
}

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

jlinkZip {
    group = 'distribution'
}

and then I updated module-info.java:

module com.github.zukarusan.app {
    requires javafx.controls;
    requires javafx.fxml;
    requires org.controlsfx.controls;
    requires com.dlsc.formsfx;
    requires org.kordamp.ikonli.javafx;
    requires org.kordamp.bootstrapfx.core;
    requires java.desktop;

    requires JTransforms; // UPDATED

    exports com.github.zukarusan.app.controller;
    exports com.github.zukarusan.app.model;
    exports com.github.zukarusan.app;
    opens com.github.zukarusan.app.controller to javafx.fxml;
}

Before I updated the module-info , the application launches just fine and shows a javafx window application. But, after I updated that, java.lang.FindException is thrown. resulting the following error:

> Task :MainApplication.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module JTransforms not found, required by com.github.zukarusan.app

Do I have to download manually the modules? or any steps that I miss?


Please enlighten me. :'(

Zukaru
  • 320
  • 2
  • 11
  • 1
    Probably you need to do something in gradle to get the JTranaforms jar on the module path (I don’t know what because I don’t use Gradle much). But, separately from the immediate issue you have, you are also trying to use jlink. From looking at the JTranaforms project, it doesn’t have a module-info.java, so it will be treated as an [automatic module](https://www.logicbig.com/tutorials/core-java-tutorial/modules/automatic-modules.html), so you will have [difficulty trying to link it](https://stackoverflow.com/questions/48408454/java-9-generating-a-runtime-image-with-jlink-using-3rd-party-jars) – jewelsea Feb 01 '22 at 06:56
  • Also, double check the actual jar names in your build folder to make sure you have the automatic module name right. Run describe module on the jar to see the derived name: `jar --file JTransforms-3.1.jar --describe-module`. – jewelsea Feb 01 '22 at 06:56
  • See the section titled “using libraries that are not modules” in the [Gradle documentation](https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_modular). By default Gradle puts those on the class path not the module path. You can’t require them in your module info unless you do some additional work like patching the dependent jar to add a module info, or you implement one of the other solutions mentioned but not really explained in the linked document.. – jewelsea Feb 01 '22 at 09:10
  • Thank you for the reply! I will try your suggestion for linking it by considering the automatic module you are mentioned – Zukaru Feb 02 '22 at 06:26

1 Answers1

1

Guided by @jewelsea in the comment, I have finally resolved this issue.

After several days, I figured out that my imported libraries in modular java project are treated as an unnamed module (correct me if I am wrong). As I understood so far, libraries like JTransforms may belong to traditional libraries that do not cover the modularity feature like in Java 9. This means that the jar library does not have Automatic-Module-Name at the very least in its manifest metadata. See the gradle documentation.

That is to say, I will have another approach using a grade plugin extra-java-module-info and found a somewhat similar case in this post.

Ultimately, I add the following script in build.gradle

plugins {
    ... // other plugins

    id 'de.jjohannes.extra-java-module-info' version '0.11'
}

extraJavaModuleInfo {
    module("JTransforms-3.1.jar", "JTransforms", "3.1") {
        exports("org.jtransforms")
    }
}

Then hit that sync button. That's all!

Cheers! Thanks again to @jewelsea.

Zukaru
  • 320
  • 2
  • 11