Reputation: 2874
I have a Maven Java project with many modules and one meta-modul. And I want to run test. I use: mvn test command in console. But my test fails when compilation, because classes in other modules are not found. But in IDE Eclipse no errors. How can I fix that?
Upvotes: 0
Views: 156
Reputation: 120761
Your models need to be free of dependency cycles!
Try to run mvn test
from the folder where the parent pom is located.
(details)
If you do not have a parent pom with sub modules. Then you must first run mvn install
for all the other of your modules where the module you want to test depends from.
(Eclipse does not need this, because it can resolve dependencies to other open projects directly)
But if all the modules belong to an single release cycle (all the modules will be released togeter with the same version) then it is may a better approach to use parent and child modules/pom -- because then you can run mvn
test or mvn install
for the parent pom, and maven will do it for all the childs in the right order. -- After you have installed all other modules, you can run mvn test on a single module until you update an other modul. -- Then you will need to install this updated modul too, or better run install for the parent.
Upvotes: 1
Reputation: 115328
Try to run mvn install
. This compile, packages and runs tests. Then when everything is compiled you can probably run mvn test
only. But you should not (IMHO) because only when you are running the full process you are sure that the newest versions of your classes are being tested. Do not worry about efficiency: maven does not compile classes if it already have them compiled. Only mvn clean install
will rebuild everything from scratch.
Upvotes: 1
Reputation: 4543
if you have well defined dependencies, use mvn install instead of mvn test. Running tests is included in install phase too and you'll get the modules you need for compilation into local maven repository.
Upvotes: 1