Home > Software design >  Java Gradle Missing libraries Modue that exists or have been imported - > Task :compileJava
Java Gradle Missing libraries Modue that exists or have been imported - > Task :compileJava

Time:05-06

So I have been facing these issues in so many JavaFX Gradle based projects in Intelli J Idea IDE. This has pushed me to the point where I had to manually download library files and make them part of my projects as a workaround.

The gradle projects I have they keeping failing when ever i run the > Task :compileJava in the IDE, for example in this particular that made me create the issue is that i have successfully imported the socket io lib from maven implementation 'io.socket:socket.io-client:2.0.1' , i have managed to import it and write a bit of sample code for it and i have added

requires engine.io.client;
    requires socket.io.client;

in the module info file . So when its time to run this fails stating that

error: module not found: socket.io.client
    requires socket.io.client;
   error: module not found: engine.io.client
    requires engine.io.client;

I have tried on JDK 13,16,17 to see if I am missing something but keeps on failing to run , so I have noticed now as a trend in my previous JavaFX project in which i managed to get away with.

So if there is anyone who understands what's wrong with Gradle set up please help.

CodePudding user response:

This answer outlines an approach rather than a concrete solution.

socket.io.client and engine.io.client are not module names.

The socket.io-client library is not Java platform modularized (as far as I can tell), so it will be an automatic module.

The name of the module will be derived from the jar name. I don't know the exact translation as the module name has . and - characters which may be remapped (or not) to make the module name valid. Try first the exact Jar file name. There can be only one module per jar.

Additionally to requiring the right name, the jar needs to be on the module path. Maven will do this automatically for automatic modules, Gradle will not. I am not a Gradle expert, so will not provide advice on how to do that for Gradle.

If you use the right name in module-info and ensure the jar is on the module path, then it may work, or it may be incompatible with the Java module system in ways that are not easily fixable by you (i.e. the broken module must be fixed by the module maintainers).

You can raise an issue for the library maintainer for them to create module-info.java files for the modules and update their documentation on how to use their libraries in a Java module environment.

If the library you are trying to use is incompatible with the Java module system when used as a module, then you could try making your project non-modular by deleting module-info.java from your project and adding appropriate command-line switches. To understand how to do this, refer to documentation on non-modular projects at openjfx.io.

  • Related