java compiler: module not found. How to inspect module resolution?

Viewed 565

When compiling my project I get a "module not found" exception. I understand what this means: apparently I have (transitively) required a module that is not on the module path. But I have not required, used or otherwise that module, as far as I can infer.

I've inspected the module-info.java, and used jar --describe-module on all jars on the compiler's module-path and nowhere I can find that missing module even mentioned. So why does the compiler think it is missing?

If a simular situation would occur in Maven, I would dump the dependency tree and see where that dependency came from. And the java executable has a --show-module-resolution for doing this at runtime, but this does not work for the compiler.

Is there any way to get more information on why the compiler thinks a module is missing?

2 Answers

The error "Module not found" is because the Java compiler is unable to find the module-info.java file. I think you have to make sure it is in the right directory path. This error indicates that the module file is not available in the module path provided.

It is not possible to ask the compiler how it constructs its modules.

As stated by Aniket, it is possible to use jdeps to analyse module dependencies. But in order to do so, jdeps needs access to all jars the compiler uses, because the dependency information is inside the jars.

There is a Maven plugin that copies all dependencies into target/dependencies. Per default it will include all scopes, including test, so one needs to be specific.

mvn dependency:copy-dependencies -DincludeScope=compile

Then you can use jdeps to analyse the modules:

jdeps -summary -recursive --class-path target/dependency/*

This will not construct a tree, but it will show what modules each module requires.

Unfortunately jdeps is not very forgiving, and will fail if only one jar is missing. IMHO it would be preferable to print what is known, including any broken reference, then fail.

Related