0

I have a script build.gradle, which created the IDEA development environment when creating a JavaFX project with Gradle support:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.10'
    id 'org.beryx.jlink' version '2.24.4'
    id 'org.javamodularity.moduleplugin' version '1.8.10' apply false
}

group 'com.prototype'
version '1.0'

repositories {
    mavenCentral()
}

ext {
    junitVersion = '5.8.2'
}

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

application {
    mainModule = 'com.prototype.simulationcrystalgrowth'
    mainClass = 'com.prototype.simulationcrystalgrowth.SimulationApplication'
}

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

dependencies {
    implementation('org.controlsfx:controlsfx:11.1.1')
    implementation('com.dlsc.formsfx:formsfx-core:11.4.2') {
        exclude(group: 'org.openjfx')
    }
    implementation('net.synedra:validatorfx:0.2.1') {
        exclude(group: 'org.openjfx')
    }
    implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
    implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
    implementation('eu.hansolo:tilesfx:17.0.11') {
        exclude(group: 'org.openjfx')
    }

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

After the "build" task is completed, the "distributions" folder appears in the build folder. It contains a zip archive with the following contents:

bin and lib folders

The bin folder contains two scripts, sh and bat. The lib folder contains, as I understand it, all the required jar modules. If JAVA_HOME is installed on Java 17 in my environment, then when executing the bat script, my program starts. I expected that jlink is a kind of analogue of a more user-friendly assembly and packaging of the application, which will help to create something like an exe application launcher.

I also noticed that there are no tasks related to jlink in build.gradle is not called during the build process using the "build" task. enter image description here

I tried to run them myself, and I got the same error: enter image description here

I am confused by the mention of the "distributions/app" path in build.gradle, I expect there should be something else after the build.

What am I doing wrong? What should I get at the output using jlink ?

  • 2
    Please don't screenshot errors. You can get the full gradle build trace as text by clicking on the root of the tree in the left column of the run window. On the right will be the build text. You can copy and paste that (or relevant portions of it) into your question formatted as code rather than as a screenshot. – jewelsea Jun 09 '22 at 21:45
  • 2
    When you run build and run in Idea, by default, it is using its internal build system which it configures when you synchronize the gradle project with Idea. It doesn't use gradle unless you ask it to by creating a specific run configuration for that (e.g. by right clicking on a grade task in the gradle window and running it). I guess that is what you did when you "tried to run them myself", so I think you already know how to run gradle tasks from the IDE rather than using the internal build system. – jewelsea Jun 09 '22 at 21:48
  • 2
    By default, the internal IDE build tasks will not use jlink because the internal tasks are for development not deployment packaging. – jewelsea Jun 09 '22 at 21:49
  • 1
    Here is a [short tutorial on jlink](https://www.baeldung.com/jlink), there are other tutorials and documentation available on the web. The structure of what jlink creates is documented in [jep 220: modular runtime images](https://openjdk.java.net/jeps/220) in the section titled "New run-time image structure". Additionally the jlink gradle plugin appears to have the ability to zip up that structure into a zip file for easier distribution. – jewelsea Jun 09 '22 at 21:53
  • 1
    You may be interested in [jpackage](https://docs.oracle.com/en/java/javase/14/jpackage/packaging-overview.html) and in the [badass jlink plugin](https://github.com/beryx/badass-jlink-plugin) for jlink or the [badass runtime plugin](https://badass-runtime-plugin.beryx.org/releases/latest/) for jpackage. – jewelsea Jun 09 '22 at 21:55

1 Answers1

0

The problem is solved.

The exclude of the org.openjfx module was removed from all dependencies.

Useful links:

https://openjfx.io/openjfx-docs/#gradle

https://github.com/openjfx/samples

https://developer.tizen.org/development/articles/openjdk-and-openjfx-installation-guide