如何发布具有项目间依赖关系的Maven多模块项目? [英] How to release Maven multi-module project with inter-project dependencies?
问题描述
让我们说我们有3层项目。数据库,业务,Web和聚合pom。
Lets say we have 3 layers project. DB, Business, Web and aggregating pom.
Project
|-DB
| |-pom.xml
|-Business
| |-pom.xml
|-pom.xml
所有模块均已发布和分支在一起,因此将Aggregator pom配置为向所有子模块分配相同的版本。我们有以下版本:
All modules are ment to be released and branched together, so Aggregator pom is configured to assign the same version to all submodules. We have the following versions:
DB-0.1-SNAPSHOT
Business-0.1-SNAPSHOT which depends on DB-0.1-SNAPSHOT
Web-0.1-SNAPSHOT which depends on Business-0.1-SNAPSHOT
release:prepare
,所有版本均更新为0.1,但是prepare失败,因为还没有依赖关系的 DB-0.1
。
When doing release:prepare
, all versions updated to 0.1, but prepare fails because there is no DB-0.1
in dependency yet.
一种解决方案是为每个模块创建不同的项目,然后使用 versions:use-releases
插件将依赖关系更新为0.1
One solution is to create different projects for every module and release them one by one while using versions:use-releases
plugin to update dependency to 0.1
但是我不喜欢这个想法,因为它需要大量的配置和脚本编写。因此,我更喜欢使用聚合并通过单个命令发布所有模块,但是问题是,正如我在上文中所述,当发布插件尝试构建 Business-0.1
时, DB-0.1
还在存储库中。
But I do not like this idea because it requires a lot of configuration and scripting. So, I prefer to use aggregation and release all modules with single command, but the problem is, as I wrote above, when release plugin tries to build Business-0.1
there is no DB-0.1
in repository yet.
有什么方法可以管理这些项目间的依赖关系?
Is there any way to manage these inter-project dependencies?
谢谢。
UPD:
即使安装目标失败。
- 数据库构建-确定(没有快照或发行版本在任何存储库中)
- 业务-失败(在存储库中未找到DB-0.1-SNAPSHOT。但是它甚至还不应该存在!)
我正在使用maven 3.0.2和发行插件2.1
I'm using maven 3.0.2 and release plugin 2.1
推荐答案
您的项目只能在父级(项目)中定义一次版本。并让所有其他模块具有父级关系。这意味着您没有汇总。而是使用多模块构建。
your project should define the version only in the parent (project) only once. And let all other modules have a parent relationship. This means you don't have a aggregation. You have a multimodule build instead.
Project
|-pom.xml (version 0.1-SNAPSHOT)
|-DB
| |-pom.xml (parent: ..)
|-Business
| |-pom.xml (parent:..)
这将解决您的问题(也许您可以以此处为例)。
This will solve your problem (May be you can take a look here as an example).
这篇关于如何发布具有项目间依赖关系的Maven多模块项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!