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

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

问题描述

我有几个项目由maven构建,我想分享一些共同的属性 - 春季版本,mysql驱动程序版本,svn基地址等 - 所以我可以更新他们一次,它将反映在所有项目。

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,所以build属性设置在那里。一切都是UTF-8。我想运行的所有报告,Sonar设置等,都在父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.

这个诀窍,我想是发布与SNAPSHOT。我会说你的发布会比你的更改频繁得多。所以,您执行您的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天全站免登陆