问题描述
我有以下Maven组织:
I have the following Maven organization:
- ./pom.xml (top-level project, which defines the 4 modules below)
- ./a/pom.xml (jar)
- ./b/pom.xml (jar)
- ./c/pom.xml (war)
- ./d/pom.xml (war)
到目前为止,我一直在按以下方式使用Maven(全部在根目录中执行):
So far, I have been using Maven as following (all executed in the root):
1. mvn clean compile install
2. mvn tomcat7:redeploy -pl c
3. mvn tomcat7:redeploy -pl d
尽管这种方法很完美,但我不确定这是否是首选方法.第一步,我要安装所有项目,但实际上,应该只安装jar项目a
和b
.无需安装c
和d
项目.
Although this works perfectly, I am not really sure if this is the preferred way. In the first step, I am installing all projects, but actually, only the jar projects a
and b
should be installed. There is no need to install the c
and d
projects.
尽管安装c
和d
并没有什么坏处,但是Maven是否有更好的用法来避免这种情况?我总是可以手动安装a
和b
,但这当然会损害模块的好处(自动检测依赖关系顺序,这只是其中的一个好处).
Although it doesn't hurt installing c
and d
, is there a better usage of Maven to avoid this? I can always manually install a
and b
, but this ofcourse conterfeits the benefits of modules (auto-detection of dependency order, to name one benefit).
推荐答案
compile
和install
都是默认生命周期的一部分,因此无需调用compile
.而且如果依赖项是反应堆的一部分(即正在构建的所有Maven项目),则不需要install
文件.相反,package
就足够了,尽管在有集成测试的情况下我更喜欢verify
.您可能也可以这样做:mvn verify tomcat7:redeploy -pl c -am
,其中-am
触发构建c所需的多模块项目的项目.
compile
and install
are both part of the default lifecycle, so there's no need to call compile
. And you don't need to install
files in case dependencies are part of the reactor (i.e. all the maven projects being built). Instead package
is good enough, although I prefer verify
in case there are integration-tests.You could probably do this as well: mvn verify tomcat7:redeploy -pl c -am
, where -am
triggers projects of the multimodule project which are required to build c.
这篇关于Maven-有关使用多模块(jar,war等)项目的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!