Error: module not found: org.controlsfx.controls - java

At first I am a beginner in the module system of Java... I want to connect org.controlsfx.controls library to my app as module. I've created the next module-info.java in my project:
module yummy {
requires org.controlsfx.controls;
requires javafx.controls;
requires javafx.fxml;
opens com.contedevel.yummy.gui to javafx.fxml;
opens com.contedevel.yummy.control to javafx.fxml;
exports com.contedevel.yummy;
}
And build.gradle:
plugins {
id 'application'
id "org.beryx.jlink" version "2.17.5"
}
group 'com.contedevel'
version '1.0-SNAPSHOT'
application {
mainClassName = 'com.contedevel.yummy.App'
applicationName = 'yummy'
applicationDefaultJvmArgs = [
"--add-opens=javafx.base/com.sun.javafx.runtime=org.controlsfx.controls",
"--add-opens=javafx.base/com.sun.javafx.collections=org.controlsfx.controls",
"--add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls",
"--add-opens=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls",
"--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls",
"--add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls",
"--add-opens=javafx.controls/com.sun.javafx.scene.control=org.controlsfx.controls",
"--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls",
"--add-opens=javafx.controls/javafx.scene.control.skin=org.controlsfx.controls"
]
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'yummy'
}
jpackage {
resourceDir = file("$buildDir/resources")
}
}
repositories {
mavenCentral()
}
dependencies {
implementation('org.controlsfx:controlsfx:11.0.1') {
exclude group: 'org.openjfx'
}
compile 'org.webjars:font-awesome:5.13.0'
testCompile 'junit:junit:4.12'
}
But when I launch my app (./gradlew run) I get the error:
yummy/src/main/java/module-info.java:2: error: module not found: org.controlsfx.controls
requires org.controlsfx.controls;
The most interesting is IntelliJ IDEA doesn't show any errors in module-info.java.
How to connect org.controlsfx.controls as module?
P.S. I don't need to connect OpenJFX modules because I use Liberica 14 with built-in OpenJFX

Related

Gradle JavaFX Jlink : duplicate module on application module path

I have a project working with gradle and everything build and run perfectly but I have issues packaging my application. I work on WSL and would like to have both linux and windows executables but to begin having one is okay I don't really care as long as it works and I can understand how to replicate it on the other OS.
So far, I have read a lot of things on the internet and tried to use this plugin in order to package my application. But when I use gradle jlink, I am warned about a duplicate module issue as you can see below. I have tried many things but cannot find anythign which works or a similar problem on the web. Would you have any clue on what I may be overlooking because of my inexperience?
Thank you in advance !
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
Here is my gradle.build file :
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']
}
}
And my module-info file :
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;
}
I had the same problem, and I found out, that the folder build/jlinkbase/jlinkjars contained mentioned modules for both platform - mac (which I use to develop) and win.
after reading https://github.com/openjfx/javafx-gradle-plugin/issues/65 I just needed to identify the "polluting" library and applied the fix, which was mentioned:
implementation (....) { exclude group:org.openjfx }

IntelliJ doesn't recognize class of gradle dependency

I have the following problem. I added the AnimateFX dependency via "Dependencies" tab in IntelliJ IDEA when I try to use one of the classes, it won't recognize it. Intellisense wont't list it either.
IntelliJ Screen Shot
Does anyone have an idea, what the actual problem here is?
To reproduce:
Create new JavaFX project via File - New - Project... choose Gradle as Build System and jdk-15(I downloaded it via IntelliJ) as Project SDK:
Project Setup
Click Next, don't add any dependencies shown in the following dailog: Dependencies Setup
Click Finish
After project configuration is finished, open gradle.build and add the following implementation statement to dependencies
implementation 'io.github.typhon0:AnimateFX:1.2.1'
Load gradle changes
Go to a .java class file that is in the src folder and try to use any class of the AnimateFX dependency, e.g.:
FadeIn fadeInTransition = new FadeIn(anyNode);
IntelliJ should now give an error stating the following: Error
IntelliJ version: IntelliJ IDEA 2021.2.2 (Community Edition) - Build #IC-212.5284.40
Gradle version: 7.1.1
Also, this is the content of my gradle.build:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
}
group 'de.mwllpr'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
sourceCompatibility = '15'
targetCompatibility = '15'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'de.mwllpr.application'
mainClass = 'de.mwllpr.application.GameApplication'
}
javafx {
version = '15.0.1'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.14.1'
implementation 'io.github.typhon0:AnimateFX:1.2.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.mockito:mockito-core:3.12.4'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
and module-info.java:
module de.mwllpr.application {
requires javafx.controls;
requires javafx.fxml;
requires org.apache.logging.log4j.core;
requires org.apache.logging.log4j;
opens de.mwllpr.application to javafx.fxml;
exports de.mwllpr.application;
}
Zipped demo project: http://www.filedropper.com/demofx

What is causing this "jpackage does not exist" error?

I'm trying to make an installer from my Gradle + JavaFX project using jpackage but the following error occurs:
Execution failed for task ':jpackageImage'.
> /home/jonander/.gradle/daemon/6.8/null/bin/jpackage does not exist.
This is my module.info:
module Seftic.main {
requires java.sql;
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
}
This is my configuration in build.gradle:
plugins {
id 'java'
id 'org.beryx.jlink' version '2.24.1'
id 'org.openjfx.javafxplugin' version '0.0.10'
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml','javafx.base' ]
}
What is causing this error, and how can it be fixed?
Don't know if anyone found a better solution but, you could set jpackageHome to your JDK install, in your build.gradle:
jlink {
jpackage {
jpackageHome = '/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home'
installerType = 'dmg'
}
}

How to force gradle to add dependencies to the module path instead of the class path in eclipse?

I have a gradle javafx library which build.gradle lokks like this :
plugins {
id 'java-library'
id 'java-library-distribution'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
repositories {
mavenCentral()
jcenter()
}
jar {
archiveName = 'streampi-fx'
}
distributions {
main {
distributionBaseName = 'streampi-fx'
contents {
from 'src/main'
}
}
}
javafx {
version = "14"
modules = [ "javafx.controls", "javafx.fxml" ]
}
with a module-info requiring javafx :
module fr.streampi.fx {
exports fr.streampi.fx.view.icons;
exports fr.streampi.fx.model;
exports fr.streampi.fx.model.io;
exports fr.streampi.fx.model.utils;
exports fr.streampi.fx.view;
requires javafx.base;
requires javafx.controls;
requires transitive javafx.graphics;
}
I'm running my project in eclipse but every time I refresh the project, all dependencies are put to the class path instead of the module path. I then have to put them back manually in the module path every time my projects refreshes. How to make gradle set the dependencies in the module path ?
I am using this one in my root build.gradle (with Gradle 6.7)
subprojects {
apply plugin: "java"
java {
modularity.inferModulePath = true
}
repositories {
jcenter()
}
}

Gradle jlink plugin fails during createMergedModule with "the service implementation does not have a default constructor"

I'm using Gradle (4.10.3, but I've tried most versions up through 5.4.1) with JDK 12.0.1 and the org.beryx.jlink plugin (2.10.4), but am running into this error every time I attempt to create the jlink image:
-> Task :createMergedModule
Cannot derive uses clause from service loader invocation in:
com/fasterxml/jackson/databind/ObjectMapper$2.run().
Cannot derive uses clause from service loader invocation in:
com/fasterxml/jackson/databind/ObjectMapper.secureGetServiceLoader().
Cannot derive uses clause from service loader invocation in:
org/apache/commons/compress/utils/ServiceLoaderIterator.().
C:\Users\MyName\IdeaProjects\myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:393:
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;
C:\Users\MyName\IdeaProjects\myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:394:
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;
2 errors
-> Task :createMergedModule FAILED
When I click through to the lines throwing the errors in the merged module-info.java, it points to these two:
provides org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface with org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath;
provides org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface with org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery;
My build.gradle file looks like this:
plugins {
id 'application'
id 'idea'
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.7'
id 'org.beryx.jlink' version '2.10.4'
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.commons:commons-csv:1.6'
compile 'org.apache.poi:poi-ooxml:4.1.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.5.0-M1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.5.0-M1'
}
// ### Application plugin settings
application {
mainClassName = "$moduleName/path.to.myapp"
}
// ### Idea plugin settings
idea {
module {
outputDir = file("out/production/classes")
}
}
// ### Java plugin settings
sourceCompatibility = JavaVersion.VERSION_11
compileJava {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
test {
useJUnitPlatform()
testLogging {
events 'PASSED', 'FAILED', 'SKIPPED'
}
}
// ### JavaFX plugin settings
javafx {
version = "12.0.1"
modules = ['javafx.controls', 'javafx.fxml']
}
// ### jlink plugin settings
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'myapp'
}
}
Any ideas on how I can address this?
The following possible solution is based just on your build file, without knowing about your module-info or the project's code, so it might not work.
It is also based on this issue at the jlink plugin's repository.
First, let me explain how this plugin works: since the (JDK) jlink tool doesn't allow non-modular dependencies, the plugin will try to collect all of them and create on the fly a module, that can be added to the module-path. This module is named $yourModuleName.mergedModule.
Now I'm adding your dependencies to a simple JavaFX project. When I run ./gradlew jlink I get the same errors you have posted. If you check the errors:
myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:394: error
This shows that the created module is named myapp.merged.module, and that it has a module-info descriptor. If you open it you will see all the exports (the module will export every package of the dependencies by default), the requires and the provides:
open module myapp.merged.module {
exports com.fasterxml.jackson.annotation;
exports com.fasterxml.jackson.core;
exports com.fasterxml.jackson.core.async;
...
exports schemaorg_apache_xmlbeans.system.sXMLTOOLS;
requires java.xml.crypto;
requires java.logging;
requires java.sql;
requires java.xml;
requires java.desktop;
requires java.security.jgss;
requires jdk.javadoc;
uses java.nio.file.spi.FileSystemProvider;
provides com.fasterxml.jackson.core.JsonFactory with com.fasterxml.jackson.core.JsonFactory;
provides com.fasterxml.jackson.core.ObjectCodec with com.fasterxml.jackson.databind.ObjectMapper;
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;
}
So now the question is: should you add some more requirements to your own module? The answer is explained here: that will increase unnecessary your project's size. A better way is to use the mergedModule script block:
The mergedModule block allows you to configure the module descriptor of the merged module
And:
the module descriptor is created using the algorithm implemented by the suggestMergedModuleInfo task.
If you run ./gradlew suggestMergedModuleInfo you will basically get the same contents for the merged module descriptor as above.
A possible solution is to start just adding some requires to the merged module descriptor, and try again.
I started with:
jlink {
mergedModule {
requires "java.xml"
}
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'myapp'
}
}
and I could run ./gradlew jlink successfully.
If you check the merged module descriptor now, it will look like:
open module myapp.merged.module {
requires java.xml;
exports com.fasterxml.jackson.annotation;
exports com.fasterxml.jackson.core;
exports com.fasterxml.jackson.core.async;
...
exports schemaorg_apache_xmlbeans.system.sXMLTOOLS;
}
containing only the explicit requires, all the exports, but without provides, so the errors will be gone.
Since I don't have your code, I can't say if this will work for you, but it did for me with the same dependencies.

Categories