我们使用 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
发布评论
评论(3)
为环境创建不同的工件并使用参数作为分类器。所有三个工件的 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.
显然,Maven 在安装 POM 时不会进行任何变量/属性替换。按原样安装,就是这个原理。你最好不要从 POM 中读取任何属性(除非这是版本号),而应该在外部文件中配置你的属性(每个阶段一个,例如
dev.properties
、test.properties)。属性
,...),然后配置 Maven 配置文件(同样,每个阶段一个)并根据您想要构建的内容调用 Maven,如mvn -Pdev
。在配置文件中,您可以使用您喜欢的任何属性打包最终应用程序(例如,借助build-helper-maven-plugin:add-resource
或maven-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 likemvn -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 ofbuild-helper-maven-plugin:add-resource
ormaven-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).
您应该为不同的 创建档案单个构建中的目标,并如前所述使用分类器将这些工件彼此分开。
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.