Maven 变量未替换到已安装的 pom 文件中

发布于 2024-12-29 05:04:18 字数 300 浏览 2 评论 0 原文

我们使用 Maven(3.0.3) 作为构建工具,我们需要针对不同的环境(DEV、TEST、QA)使用不同的版本。如果我们在构建时根据环境传递 version 属性值,则安装的 POM 不会具有传递的属性值,而是仍然具有 ${app-version} 字符串。

我已经看到这个 http://jira.codehaus.org/browse/MNG- 存在一个错误 2971

2971章

第 维杰

We are using Maven(3.0.3) as build tool and we need to have different version for different environments (DEV , TEST, QA ) . If we pass version property value during build time based on environment , the installed POM doesn't have the passed property values instead it still has the ${app-version} string.

I saw already there is a bug for this http://jira.codehaus.org/browse/MNG-2971

Is there any other alternative ,because we cannot different POM file for different environments ,which will be hard to maintain..

Thanks
Vijay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我们的影子 2025-01-05 05:04:18

为环境创建不同的工件并使用参数作为分类器。所有三个工件的 pom 都是相同的,但分类器将它们分开。

Create different artifacts for the environments and use the parameter as a classifier. The pom is the same for all three artifacts but the classifier separates them.

绝不服输 2025-01-05 05:04:18

显然,Maven 在安装 POM 时不会进行任何变量/属性替换。按原样安装,就是这个原理。你最好不要从 POM 中读取任何属性(除非这是版本号),而应该在外部文件中配置你的属性(每个阶段一个,例如 dev.propertiestest.properties)。属性,...),然后配置 Maven 配置文件(同样,每个阶段一个)并根据您想要构建的内容调用 Maven,如 mvn -Pdev 。在配置文件中,您可以使用您喜欢的任何属性打包最终应用程序(例如,借助 build-helper-maven-plugin:add-resourcemaven-antrun-plugin + 复制规则)。

或者,您可以过滤您的资源。例如,您可以过滤 Spring 上下文 XML 文件,该文件引用属性文件(因此您打包了所有属性文件,但 Spring 将仅引用某些特定文件)。或者,您可以过滤另一个属性文件,从中您将了解要使用的“主”属性文件(双重间接)。

Apparently Maven does not make any variable/property substitution when installing the POM. It is installed as is, that is the principle. You'd better not read any properties from POM (unless this is e.g. version number), bout you should configure your properties in external file (one per stage, e.g. dev.properties, test.properties, ...) and then configure Maven profiles (again, one per stage) and invoke Maven like mvn -Pdev depending on what you want to build. In profile you can package your final application with whatever properties you like (e.g. with the help of build-helper-maven-plugin:add-resource or maven-antrun-plugin + copy rule).

Alternatively you can filter your resources. For example, you can filter your Spring context XML file, which refers the properties file (so you package all property files, but Spring will refer only some specific). Or you can filter another properties file from which you will learn what is the "main" properties file to use (double indirection).

挽手叙旧 2025-01-05 05:04:18

您应该为不同的 创建档案单个构建中的目标,并如前所述使用分类器将这些工件彼此分开。

You should create the archives for your different targets within a single build and use as already mentioned the classifier to separate those artifacts from each others.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文