openjfx / javafx-gradle-plugin

Gradle plugin that makes it easy to work with JavaFX 11+
https://openjfx.io/
BSD 3-Clause "New" or "Revised" License
358 stars 62 forks source link

Application run cannot find javafx.web module on Java 17 #117

Open DJViking opened 2 years ago

DJViking commented 2 years ago

The Gradle Application Plugin run task doesn't work when running with Java 17. Works fine on Java 11, but when updated to run Java 17 and JavaFX 17, I get java.lang.module.FindException: Module javafx.web not found

Workaround: Remove the javafxplugin Add JavaFX dependencies

I wonder if there is still any use for this plugin. It saves a few more lines, but seems to do just the same as my workaround.

abhinayagarwal commented 2 years ago

Do you have an example build.gradle without using the plugin?

nlisker commented 2 years ago

I am encountering this (or a similar) problem.

For comparison, I'm using both Eclipse and Gradle to run and build.

test.zip

version 0.0.11

Building

Eclipse: builds fine

Gradle build tasks fails:

Working Directory: C:\Users\Nir\workspaceSmallStuff\test
Gradle user home: C:\Users\Nir\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 7.4
Java Home: C:\Program Files\Java\jdk-15
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: :build

> Configure project :
Project : => 'testproj' Java module

> Task :generateEffectiveLombokConfig
> Task :compileJava UP-TO-DATE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :startScripts UP-TO-DATE
> Task :distTar UP-TO-DATE
> Task :distZip UP-TO-DATE
> Task :assemble UP-TO-DATE
> Task :mergeClasses SKIPPED
> Task :generateTestEffectiveLombokConfig
> Task :compileTestJava UP-TO-DATE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
Could not write standard input to Gradle Test Executor 25.
java.io.IOException: The pipe is being closed
    at java.base/java.io.FileOutputStream.writeBytes(Native Method)
    at java.base/java.io.FileOutputStream.write(FileOutputStream.java:347)
    at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
    at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)
    at org.gradle.process.internal.streams.ExecOutputHandleRunner.forwardContent(ExecOutputHandleRunner.java:68)
    at org.gradle.process.internal.streams.ExecOutputHandleRunner.run(ExecOutputHandleRunner.java:53)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)

> Task :test FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.web not found, required by com.gluonhq.charm.glisten.connect.view

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> Process 'Gradle Test Executor 25' 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 1s
9 actionable tasks: 3 executed, 6 up-to-date

So, the same java.lang.module.FindException: Module javafx.web not found that was reported.

Running

Eclipse: run fails:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module com.gluonhq.charm.glisten not found, required by testproj

Gradle run task runs fine

Testing

Eclipse: Running the test as JUnit fails with the same run message

Gradle test fails with the same build error

version 0.0.12

Change in the build file to this version and do "refresh gradle project".

Building

Eclipse: errors: no module in the module-info file can be resolved.

Gradle build tasks fails as with 0.0.11

Running

Eclipse: fails with

Error occurred during initialization of boot layer
java.lang.module.FindException: Module testproj not found

Gradle run task runs fine

Testing

Eclipse: Running the test as JUnit fails with

WARNING: Unknown module: testproj specified to --patch-module
WARNING: Unknown module: testproj specified to --add-reads
WARNING: Unknown module: testproj specified to --add-opens
Class not found mytest.MyTest
java.lang.ClassNotFoundException: mytest.MyTest
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:766)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:490)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:513)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Gradle test fails with the same build error


So it seems like version 0.0.12 broke something, but in version 11 there were also issues. Could be something else in the build, but don't know what.

nlisker commented 2 years ago

@abhinayagarwal Can you have a look at the reproduction cases? I tested both 0.0.11 and 0.0.12 with a sample project.

HEdingfield commented 2 years ago

Similar problem for me running JDK 17 and trying to upgrade from 0.0.11 to 0.0.12 or 0.0.13 and then using gradle run inside IntelliJ:

WARNING: Unknown module: my.project specified to --patch-module
Error: Could not find or load main class my.project.Main
Caused by: java.lang.ClassNotFoundException: my.project.Main
Execution failed for task ':run'.
> Process 'command 'C:\Java\jdk-17.0.2\bin\java.exe'' finished with non-zero exit value 1
abhinayagarwal commented 2 years ago

@nlisker Can you confirm if you are still facing this issue in 0.0.13 and JFX 19 ?

bademux commented 2 years ago

@abhinayagarwal I have the same issue "Could not find or load main" in 0.0.13 and JFX 19 (JDK17)

Artenes commented 2 years ago

Same thing here, I am using:

But the problem goes away when downgrading to JFX gradle plugin 0.0.11.

Note that this problem only happens when we add a module-info.java under src/main/java. If the file is removed from there it works with latest version.

nlisker commented 2 years ago

@abhinayagarwal Let's look at this sample so we have a common ground: https://github.com/openjfx/samples/tree/master/IDE/Eclipse/Modular/Gradle/hellofx (or for other IDEs, I personally use this one because I use Eclipse).

I only updated the JavaFX version to 19, grade wrapper to 7.5.1 and 'org.beryx.jlink' to version '2.25.0'. Gradle runs on Java 18 (better to add toolchain support in these examples so Gradle and the application can use different Java versions). The results are: 'org.openjfx.javafxplugin' version '0.0.11': builds and runs using gradle. 'org.openjfx.javafxplugin' version '0.0.12': builds but fails on run with

Error: Could not find or load main class hellofx.org.openjfx.MainApp
Caused by: java.lang.ClassNotFoundException: hellofx.org.openjfx.MainApp

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\Java\jdk-18\bin\java.exe'' finished with non-zero exit value 1

'org.openjfx.javafxplugin' version '0.0.13': same as '0.0.12'

With this sample you can test directly what works and what doesn't.

pellico commented 1 year ago

I hit the same issue :-(

miasma commented 1 year ago

Same issue here. I tried different combinations of versions with the @nlisker's hellofx example:

miasma commented 1 year ago

I did some further testing. This commit seems to break the plugin: https://github.com/openjfx/javafx-gradle-plugin/commit/02d36b8f1cbac46c8faeb01ade45f399c37eb9fd

Moduleplugin versions 1.8.2 - 1.8.9 all work, but 1.8.10 triggers the bug, also 1.8.11 and 1.8.12 fail.

miasma commented 1 year ago

@nlisker. Ok added this to build.gradle:

application {
    mainModule = moduleName
    mainClass = "org.openjfx.MainApp"
    applicationDefaultJvmArgs = ['--module', 'hellofx']
}
//mainClassName = "$moduleName/org.openjfx.MainApp"

Now it works with Java 19, Gradle 8.0.1 and JavaFX 19.0.2. Apparently this change (https://github.com/java9-modularity/gradle-modules-plugin/commit/fda9c7e98f85924ad6e690f1d48eb38b5cadae50#diff-ae589711150c3780c06898bd2c6583a49c3bfe8f6918f6f4549ade459fd500aa) in moduleplugin 1.8.10 affects Gradle versions 6.4+. A wrong module name gets passed to --module? Manually overriding it seems to fix it for me.

edit: now that I tried it again, I noticed that I had forgotten to comment out the mainClassName while testing at first. So the applicationDefaultJvmArgs override might not be necessary - users of Gradle 6.4+ should just use the mainModule/mainClass combo instead of mainClassName. Gradle 6.4+ changed the way main class/module names are passed. I think the moduleplugin has some code to warn about the use of the old modulename/classname scheme, but I didn't see this when using the JavaFX plugin. I think this should trigger some sort of warning because the old build configs at first seems to work, but then fails when executing the 'run' phase.

nlisker commented 1 year ago

Thanks, I'll try it out.

Maybe @abhinayagarwal can use this info to create a fix.