Maven: Why does it need dependency modules' .j

2019-08-07 12:59发布

问题:

I have a Maven-based project with modules, say,

root
  modA
  modB

Now modB depends on modA. When I run

mvn initialize help:effective-pom

it fails because modB wants modA.jar. My question is,

Why does it need the jar? All the information needed should be in pom.xml, which is available in the module.

Who want's to try, check out e.g. Hibernate Core 3.3.2.

Thanks, Ondra

回答1:

Tried this locally on a multi-module project and see that maven does not need dependency module .jars for either initialize or help:effective-pom.

It looks like there may be some plugin configuration in your pom which is causing this. Could you check and if so, update your question with the relevant pom snippet?



回答2:

When dealing with multi-module projects, you need to actually use the install goal to get pom files (and artifacts) in to your local repository. Running mvn initialize on your root pom basically causes maven to do the following to your modA and modB projects

mvn initialize -f modA/pom.xml
mvn initialize -f modB/pom.xml

If you use install it will run install on modA before modB even begins, thus ensuring that all of modA's artifacts, including it's pom, will be in your local repo. When modB runs, it will grab those artifacts, including modA's pom, from your local repository. Maven isn't "smart" enough, to know to look for modA's pom.xml relative to modB just by virtue of them being in the same multimodule project. Hence why the artifacts must be installed using the install goal first.