Maven cannot resolve dependency for module in same multi-module project Maven cannot resolve dependency for module in same multi-module project java java

Maven cannot resolve dependency for module in same multi-module project


Have you run mvn clean install at least once on the project to install the dependencies within your local repository?


The Maven reactor is weird that way, it keeps modules around only for certain tasks. When running a build target that only does something for one subproject, then even if Maven builds dependencies first, it does not keep them around in the reactor (sometimes).

Installing to the local repository is a workaround, but it is horrible and should be avoided when possible, because you can easily end up with outdated build results.

A slightly less ugly workaround is to combine two build targets, where the second build target does something harmless, but triggers addition to reactor in all subprojects.

As an example you can combine the task you want with the 'compile' or 'package' tasks.

Also see highest voted answer at Maven doesn't recognize sibling modules when running mvn dependency:tree


This error might also be caused by Maven being in offline mode.

Sometimes I seem to accidentally enable offline mode in IntelliJ IDEA. To disable it, toggle the Toggle Offline Mode toggle in the Maven Toolbar

enter image description here

or uncheck the Work Offline checkbox in the settings under Build, Execution, Deployment > Build Tools > Maven.

enter image description here