使用 Git 发布多模块 maven 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6727450/
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
Releasing a multi-module maven project with Git
提问by Josh Stone
I'm trying to release a multi-module maven project that uses git as the SCM, and among the first problems I've encountered is the way in which the maven release plugin builds the release.properties scm.url. My parent POM looks something like this:
我正在尝试发布一个使用 git 作为 SCM 的多模块 maven 项目,我遇到的第一个问题是 maven 发布插件构建 release.properties scm.url 的方式。我的父 POM 看起来像这样:
<packaging>pom</packaging>
<groupId>org.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scm>
<connection>scm:git:git://github.com/username/project.git</connection>
<developerConnection>scm:git:[email protected]:username/project.git</developerConnection>
<url>http://github.com/username/project</url>
</scm>
<modules>
<module>api</module>
<module>spi</module>
</modules>
And the module POMs are straightforward:
模块 POM 很简单:
<parent>
<groupId>org.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>api</artifactId>
<version>0.2.2</version>
My goal is to be able to release individual modules since they each have different versions and I don't want to increment all of the versions together each time I do a release.
我的目标是能够发布单个模块,因为它们每个都有不同的版本,我不想在每次发布时将所有版本都增加在一起。
When I change to the api
directory and do a mvn release:clean release:prepare
I'm met with the following output:
当我更改api
目录并执行以下操作时,mvn release:clean release:prepare
我会看到以下输出:
[INFO] Executing: cmd.exe /X /C "git push [email protected]:username/project.git/api master:master"
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to commit files
Provider message:
The git-push command failed.
Command output:
ERROR: Repository not found.
It looks like the maven release plugin creates the scm.url by appending the module name to the developerConnection
, which ends up not being a valid repository at github. I'm not sure what the right way to set this up is. It might be the case that Maven + git + releasing an individual child module simply won't work? Any input is appreciated.
看起来 maven 发布插件通过将模块名称附加到 scm.url 来创建 scm.url developerConnection
,这最终不是 github 上的有效存储库。我不确定设置它的正确方法是什么。Maven + git + 发布单个子模块可能根本行不通?任何输入表示赞赏。
采纳答案by bmargulies
To see how to make this work, have a look at a working example, such as:
要了解如何进行这项工作,请查看一个工作示例,例如:
https://github.com/sonatype/sonatype-aether
https://github.com/sonatype/sonatype-aether
However, this won't help if you like to release the individual pieces. In that case, you have to just copy the <scm> elements into all the poms.
但是,如果您想发布单个作品,这将无济于事。在这种情况下,您只需将 <scm> 元素复制到所有 poms 中。
This is an active topic of discussion on the maven dev list, but don't hold your breath for a solution from there; it's a big deal.
这是 maven dev list 上讨论的一个活跃话题,但不要屏住呼吸寻求解决方案;这是一个大问题。
回答by Gray
I found this question with a search on "git-push command failed". I have a similar configuration where I have a master-pom and then submodules that I release as their own maven packages.
我通过搜索“git-push 命令失败”发现了这个问题。我有一个类似的配置,我有一个 master-pom,然后是我作为自己的 maven 包发布的子模块。
To get it to work I had to tune the scm
section of the pom.xml
to something like the following. The connections specifically had to be tuned right to work. None of the github ones worked at all.
为了让它工作,我必须将 的scm
部分调整pom.xml
为如下所示。必须特别调整连接才能正常工作。github 上的一个根本不起作用。
<scm>
<url>https://github.com/XXX/YYY</url>
<connection>scm:git:ssh://[email protected]/XXX/YYY.git</connection>
<developerConnection>scm:git:ssh://[email protected]/XXX/YYY.git</developerConnection>
</scm>
The XXX
in the above example is your github username. You cannot use the :XXX
format ([email protected]:XXX/...
) because the value past the :
is interpreted as being a port number instead. The YYY
is obviously your repository name under the XXX
account.
在XXX
上面的例子就是你的用户名GitHub的。您不能使用:XXX
格式 ( [email protected]:XXX/...
),因为超过 的值:
被解释为端口号。该YYY
显然是在你的仓库名称XXX
帐户。
I just released all 3 of my submodules one-by-one using this pattern successfully.
我刚刚成功地使用这种模式一个一个地发布了我的所有 3 个子模块。
回答by Daniel Flower
I was trying to do a similar thing for a long time, and never found a good solution, so wrote my own release plugin for git. It only releases changed modules, you don't need any scm config, it tags based on the module names, and inter-component dependencies work.
做类似的事情尝试了很久,一直没有找到好的解决方案,所以自己写了一个git发布插件。它只发布更改的模块,您不需要任何 scm 配置,它基于模块名称进行标记,并且组件间依赖项起作用。
Documentation: http://danielflower.github.io/multi-module-maven-release-plugin/index.html
文档:http: //danielflower.github.io/multi-module-maven-release-plugin/index.html
Introduction blog: http://danielflower.github.io/2015/03/08/The-Multi-Module-Maven-Release-Plugin-for-Git.html
介绍博客:http: //danielflower.github.io/2015/03/08/The-Multi-Module-Maven-Release-Plugin-for-Git.html
回答by toschneck
A simple way, what worked for me is to use the parent properties in the modules pom.xml
like follow in the scm
tag like follow:
一种简单的方法,对我有用的是在模块中使用父属性,pom.xml
如 follow 在scm
标签中,如 follow:
<!--module pom.xml-->
<scm>
<connection>${project.parent.scm.connection}</connection>
<developerConnection>${project.parent.scm.developerConnection}</developerConnection>
</scm>
回答by Wysawyg
For anyone that comes to this question in search of a good solution as I did, what I found that works for me is the following:
对于任何像我一样寻求这个问题的人来说,我发现对我有用的是以下内容:
http://blog.avisi.nl/2012/02/15/maven-release-plugin-setup-guide-for-git/
http://blog.avisi.nl/2012/02/15/maven-release-plugin-setup-guide-for-git/
You still 'tag' off the entire trunk because that's how git works but it allows to you only build/version/deploy the submodule that you want to.
您仍然“标记”整个主干,因为这就是 git 的工作方式,但它只允许您构建/版本/部署您想要的子模块。
回答by sshekhar1980
I know this is late for a response but I ran into this same issue and the only solution where you could achieve both, a multi module maven project, and independent releases for each module is when you do the following:
我知道这已经迟到了,但我遇到了同样的问题,唯一可以同时实现多模块 maven 项目和每个模块的独立版本的解决方案是,当您执行以下操作时:
- For the maven multi-module project setup a GIT project
- For each maven module in (1) add a GIT submodule in (1)
- Link each GIT submodule (2) to a GIT project of its own
- 为 maven 多模块项目设置一个 GIT 项目
- 对于 (1) 中的每个 Maven 模块,在 (1) 中添加一个 GIT 子模块
- 将每个 GIT 子模块 (2) 链接到自己的 GIT 项目
Essentially, within git each maven module will exist as a project of its own. There will be a separate git project for the maven parent project but it will not contain the actual modules, only git submodule links to the git location where actual projects are stored.
本质上,在 git 中,每个 Maven 模块都将作为自己的项目存在。Maven 父项目将有一个单独的 git 项目,但它不包含实际模块,只有 git 子模块链接到存储实际项目的 git 位置。
回答by le0diaz
I answered to a related question here (multi-module with multi-repository). basically, you can use a property called commitByProject, since maven-release-plugin 2.0-beta-5, that lets you commit per project each submodule (referenced from root pom with 'git submodule add' strategy also works).
我在这里回答了一个相关的问题(multi-module with multi-repository)。基本上,你可以使用一个名为 commitByProject 的属性,因为 maven-release-plugin 2.0-beta-5,它允许你为每个项目提交每个子模块(从根 pom 引用,使用 'git submodule add' 策略也有效)。
mvn release:prepare -DcommitByProject=true