如何在Maven/Jenkins作业中替换POM中的属性? [英] How to replace a property in a POM in a Maven/Jenkins job?

查看:347
本文介绍了如何在Maven/Jenkins作业中替换POM中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含客户端和服务器组件的项目.两者都有自己的Maven多模块构建项目.

I have a project with client and server components. Both have their own Maven multi-module build projects.

必须在各个前端模块中引用正确的服务器版本.为此,我在客户端父POM中设置了一个属性,如下所示:

The correct server version must be referenced in various frontend modules. To accomplish this I set a property in my client parent POM like this:

<properties>
  <server.version>1.2.3</server.version>
</properties>

现在,我想在Jenkins构建作业期间/之后更新POM中的版本号 (即,不仅仅是使用-D ...从命令行注入其他版本).有办法吗?

Now I'd like to update the version number in the POM (i.e. not just injecting a different version from the command line with -D...) during/after a Jenkins build job. Is there a way to do this?

推荐答案

我找到了com.google.code.maven-replacer-plugin:replacer Maven插件,该插件非常适合我的情况.它接受一个xpath和一个正则表达式来定义要在XML文件中替换的内容.

I found the com.google.code.maven-replacer-plugin:replacer Maven plugin which works perfectly for my case. It accepts an xpath and a regex to define what to replace in an XML file.

示例插件配置:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
    <version>1.5.3</version>
    <configuration>
        <file>${project.basedir}/pom.xml</file>
        <xpath>/project/properties/server.version/text()</xpath>
        <token>^.*$</token>
        <value>${newServerVersion}</value>
    </configuration>
</plugin>

并且可以为每个受影响的maven模块运行该插件:

And the plugin can be run for each affected maven module:

mvn --non-recursive replacer:replace -DnewServerVersion=xxxx

这篇关于如何在Maven/Jenkins作业中替换POM中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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