문제

I have a multi-module Maven project where module B depends on module A. How do I get module A to be rebuilt whenever I rebuild module B? Right now I have to manually install module A before doing anything with module B and it's a real pain.

P.S. I see someone else asked a similar unanswered question: Maven: How to use jetty:run in a multi-module Maven project, without needing to install

도움이 되었습니까?

해결책

This is solved in two ways. First, the POM for B needs to include the <dependency> for A. As long as A is in the repository when B is built, it will get the correct version.

To make sure A gets built before B, the Maven reactor needs to know about this dependency. This is done in a multimodule build with <module> elements. The top-level POM is set for <packaging>pom</packaging> and it would have two <module> elements, one for A and one for B. It doesn't matter what order they are listed or how deep, if they are reachable from the source project, they will be built in the right order.

Note that there is no way to try building B and have the Maven reactor go find the source for A and check it. The reactor always needs a source project, and both A and B must be found through the graph of <module> elements. This is because the build for B cannot tell if the repository artifact for A is up-to-date, it must run A's build and let it figure it out. And for them to do so at the same time, a parent project that includes both as described here must be the source project that gets built.

Also note that while Maven is no slower than Ant for multi-module projects of this sort, importing your Maven project into an IDE will generally result in far faster builds than Maven can perform itself.

다른 팁

Working in the Eclipse IDE with m2eclipse, you can enable workspace dependency management for compile time, as well as in Maven launch configuration. In this case, compiled classes from dependent project will be used instead of the jar from the Maven local repository. That works for a regular projects without customized jar packaging.

Naturally, in the command line, you either build and install each project, or use a reactor project to build both projects in one run, but that is significantly less convenient then working in the IDE.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top