Java Maven:从多模块项目中只构建一个模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21606907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 09:38:12  来源:igfitidea点击:

Maven: Build only one module out of multi-module project

javamavenbuild

提问by sangupta

I have a multi-module Maven project wherein I just want to release an update module rather than the entire project. This is due to some specific requirements, wherein a release of entire project is uncalled for - only a subset of the library needs the fixes and thus the release.

我有一个多模块 Maven 项目,我只想发布一个更新模块而不是整个项目。这是由于某些特定要求,其中不需要发布整个项目 - 只有库的一个子集需要修复,因此需要发布。

However, when I run a mvn release:prepareI get the following error Non-resolvable parent POM- I have setup the parent POM relationship in the module project with relativePathtag but that does not seem to work.

但是,当我运行 a 时,出现mvn release:prepare以下错误Non-resolvable parent POM- 我在模块项目中设置了带有relativePath标签的父 POM 关系,但这似乎不起作用。

Is it possible to release only a module rather than releasing the entire project.

是否可以只发布一个模块而不是发布整个项目。

Thanks in advance.

提前致谢。

EDIT

编辑

Parent pom

父 pom

<groupId>com.domain</groupId>
<artifactId>project-parent</artifactId>
<version>0.5.1-SNAPSHOT</version>

<packaging>pom</packaging>

<modules>
    <module>library1</module>
    <module>library2</module>
    <module>library3</module>
</modules>

The module POMs are as under:

模块 POM 如下:

<parent>
    <groupId>com.domain></groupId>
    <artifactId>project-parent</artifactId>
    <version>0.5.1-SNAPSHOT</version>
</parent>

<artifactId>library1</artifactId>

Now I just want to release the new version of library1 and not others

现在我只想发布 library1 的新版本而不是其他版本

回答by matt b

Try running the maven commands from the parent project/directory with the -pl <project name>switch.

尝试从与父项目/目录下运行Maven的命令-pl <project name>开关

回答by Konstantin

I think maven is trying to tell you that the parent you defined is not released/stable. In your pom the parent version is "0.5.1-SNAPSHOT" which can not/should not work if you want to release a single library module as it would be pointing to something that is not uniquely defined. Is there a stable version you can point to instead? Otherwise maybe the -am switch works in combination with -pl?

我认为 maven 试图告诉您您定义的父级未发布/稳定。在你的 pom 中,父版本是“0.5.1-SNAPSHOT”,如果你想发布一个库模块,它不能/不应该工作,因为它会指向没有唯一定义的东西。是否有您可以指向的稳定版本?否则也许 -am 开关与 -pl 结合使用?

Edit

编辑

I tried this just now with maven 3.2 and it does ask me for what version the parent should be set/resolved to. It is as I stated previously you need stable version numbers for the release to work

我刚刚用 maven 3.2 尝试过这个,它确实问我应该将父级设置/解析为哪个版本。正如我之前所说,您需要稳定的版本号才能使发行版正常工作

mvn release:prepare -pl library1
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building library1 1.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.3.2:prepare (default-cli) @ library1 ---
[INFO] Verifying that there are no local modifications...
[INFO]   ignoring changes on: **\release.properties, **\pom.xml.next, **\pom.xml.releaseBackup,     **\pom.xml.backup, **\pom.xml.branch, **\pom.xml.tag [INFO] Executing: cmd.exe /X /C "git status"
[INFO] Working directory: C:\temp\mavenTest\library1
[INFO] Checking dependencies and plugins for snapshots ...
There are still some remaining snapshot dependencies.
: Do you want to resolve them now? (yes/no) no: : yes
Dependency type to resolve,: specify the selection number ( 0:All 1:Project Dependencies 2:Plugins 3:Reports 4:Extensions ): (0/1/2/3) 1: : 1
Dependency 'testme:parent' is a snapshot (1.1-SNAPSHOT)
: Which release version should it be set to? 1.1: :

回答by Gene

mvn -pl .,library1 clean install

The "." will build your parent pom.xml and "library1" is the module name you gave it.

这 ”。” 将构建您的父 pom.xml,“library1”是您给它的模块名称。

If you don't want to build the parent pom.xml, you can also do:

如果你不想构建父 pom.xml,你也可以这样做:

mvn -pl library1 clean install

or in your case, maybe:

或者在你的情况下,也许:

mvn -pl library1 deploy

I used "deploy" because "release" is not a Maven build lifecycle phase.

我使用“部署”是因为“发布”不是 Maven 构建生命周期阶段。

回答by mmoossen

the trick is both:

诀窍是:

  1. to repeat the -pl Param inside an additional -Darguments Param, to pass the -pl Param to the Child-Maven-Processes
  2. the mysterious mavenExecutor, to be able to create the Child-Maven-Processes using the given -pl Param
  1. 在附加的 -Darguments 参数中重复 -pl 参数,将 -pl 参数传递给 Child-Maven-Processes
  2. 神秘的 mavenExecutor,能够使用给定的 -pl Param 创建 Child-Maven-Processes

This should work:

这应该有效:

mvn -pl library1 -DmavenExecutorId=forked-path -Darguments="-pl library1"