Maven模块+构建单个特定模块 [英] Maven Modules + Building a Single Specific Module
问题描述
我有一个多模块Maven项目,父项目 P
和三个子模块 A
, B
, C
。 B
和 C
都是war项目,都依赖于 A
。
I have a multi-module Maven project with a parent project P
and three sub-modules A
, B
, and C
. Both B
and C
are war projects and both depend on A
.
我可以在 P
中键入 mvn compile
并拥有所有子模块都经过适当编译。当我想对特定模块进行操作时会出现问题。
I can type mvn compile
in P
and have all of the sub-modules properly compiled. The problem comes when I want to do operations for specific modules.
我希望能够打包项目的战争 B
,但是当我从 B
的目录运行package命令时,它会抱怨它无法找到 A的依赖项
。
I'd like to be able to package a war for project B
, but when I run the package command from B
's directory, it complains that it can't find the dependencies for A
.
我从这个问题中理解: Maven和依赖模块或许Maven并不是真的设计用于这种类型的依赖项解析,但这引出了如何打包 B
的问题?
I understand from this question: Maven and dependent modules that perhaps Maven isn't really designed for this type of dependency resolution, but that begs the question of how do I package B
?
-
我是否必须为整个项目层次结构运行
mvn package
当我真的只想B
?
每次打包 B
时,是否必须将A的快照安装到本地存储库中?
Do I have to install snapshots of A into my local repository every time I want to package B
?
当 A
时,第二种情况并不是很有趣仍在积极开发中。
This second scenario isn't much fun when A
is still under active development.
这里有什么最佳做法?
推荐答案
这里有哪些最佳做法?
Any best practices here?
使用Maven 高级反应堆选项,更具体地说:
Use the Maven advanced reactor options, more specifically:
-pl, --projects
Build specified reactor projects instead of all projects
-am, --also-make
If project list is specified, also build projects required by the list
所以只需 cd
进入父P目录并运行:
So just cd
into the parent P directory and run:
mvn install -pl B -am
这将构建B和B所需的模块。
And this will build B and the modules required by B.
这篇关于Maven模块+构建单个特定模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!