Maven 模块 + 构建单个特定模块 [英] Maven Modules + Building a Single Specific Module

查看:36
本文介绍了Maven 模块 + 构建单个特定模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多模块 Maven 项目,其中包含一个父项目 P 和三个子模块 ABC.BC 都是战争项目,都依赖于 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 打包一个 war,但是当我从 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?

  1. 当我真的只想要 B 时,我是否必须为整个项目层次结构运行 mvn package?

  1. Do I have to run mvn package for the entire project hierarchy when I really just want 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?

推荐答案

这里有什么最佳实践吗?

Any best practices here?

使用 Maven 高级反应器选项,更具体地说:

-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.

请注意,如果您要引用与目录名称不同的 artifactId,则需要使用冒号:

Note that you need to use a colon if you are referencing an artifactId which differs from the directory name:

mvn install -pl :B -am

如此处所述:

这篇关于Maven 模块 + 构建单个特定模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆