如何在几个 Maven 项目之间共享公共属性? [英] How to share common properties among several maven projects?

查看:61
本文介绍了如何在几个 Maven 项目之间共享公共属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个maven构建的项目,我想分享其中的一些共同属性——spring版本、mysql驱动版本、svn base url等——这样我就可以更新一次,它会反映在所有项目中.

I have several projects built by maven, and I want to share some common properties among them - spring version, mysql driver version, svn base url, etc. - so I can update them once and it will be reflected on all projects.

我想拥有一个具有所有属性的超级 pom,但是如果我更改其中一个问题,我需要增加它的版本(并更新从它继承的所有 pom)或从所有开发人员那里删除它' 我不想做的机器.

I thought of having a single super pom with all the properties, but if I change one of the problem I need to either increment its version (and to update all the poms inherit from it) or to delete it from all the developers' machines which I don't want to do.

可以在 pom 外部指定这些参数吗?我仍然希望在父 pom 中有外部位置定义.

Can specify these parameters externally to the pom? I still want to have the external location definition in a parent pom.

推荐答案

请注意,我在这里的最初想法是我正在做的事情,但我可能已经找到了一个更好的想法,我也已经下面列出.为了完整起见,我想保留这两个想法,以防较新的想法行不通.

我认为你可以使用父 pom 来解决这个问题,但是你需要有一个 maven 仓库和一个 CI 构建工具.

I think you can solve this problem using the parent pom, but you need to have a maven repository and a CI build tool.

我有几个项目,它们都从父 POM 继承基本属性.我们使用 Java 1.5,以便在那里设置构建属性.一切都是UTF-8.我希望运行的所有报告、声纳设置等都在父 POM 中.

I've got several projects which all inherit base properties from a parent POM. We use Java 1.5, so that build property is setup there. Everything is UTF-8. All of the reports that I wish to run, Sonar setup, etc, is inside the parent POM.

假设您的项目在版本控制中并且您有一个 CI 工具,当您签入时,您的 CI 工具可以构建到 POM 项目并将 SNAPSHOT 部署到 maven 存储库.如果您的项目指向父 POM 的 SNAPSHOT 版本,他们将检查存储库以验证他们是否拥有最新版本……如果没有,他们会下载最新版本.因此,如果您更新父项,所有其他项目都会更新.

Assuming your project is in version control and you've got a CI tool, when you check in, your CI tool can build to POM project and deploy the SNAPSHOT to the maven repos. If your projects point to the SNAPSHOT version of the parent POM, they'll check the repository to validate that they have the latest version...if not they download the latest version. So if you update the parent, all of the other projects will update.

诀窍,我想是通过快照发布.我想说您的发布将比您的更改少得多.因此,您执行 POM 的发布,然后更新从它们继承的 POM 并将它们签入版本控制.让开发人员知道他们需要进行更新并从那里开始.

The trick, I suppose is releasing with a SNAPSHOT. I'd say your releases are going to come much less frequently than your changes. So you perform a release of your POM, then update your POMs that inherit from them and check them into version control. Let the devs know that they need to do an update and go from there.

您可以在那里触发构建,强制将新 POM 放入存储库,然后让所有开发人员在构建时自动获取更改.

You could just trigger builds there forcing the new POMs into the repository and then have all of the devs pick up the changes automagically upon build.

我删除了 LATEST/RELEASE 关键字创意,因为它们不适用于父 POM.它们仅适用于依赖项或插件.问题区域在 DefaultMavenProjectBuilder 中.本质上,它无法确定要查找父存储库以确定最新版本或发布版本是哪个存储库.不知道为什么这对于依赖项或插件是不同的.

I've removed the LATEST/RELEASE keywords idea because they do not work for parent POMs. They only work for dependencies or plugins. The problem area is in DefaultMavenProjectBuilder. Essentially it has trouble determining which repository to look for the parent to determine what the latest or release version is. Not sure why this is different for dependencies or plugins though.

听起来这比每次更改父 POM 时都要更新 POM 更痛苦.

It sounds like these would be less painful than having to update the POMs on every change to the parent POM.

这篇关于如何在几个 Maven 项目之间共享公共属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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