如何在 spring 项目的终端中更新 pom.xml 属性?

How can I update a pom.xml property in terminal in spring project?

说,我的spring项目中的pom.xml里有个属性customProp。 2.4.snap

当我 运行 我的项目时,我可以像下面这样更新它的值

mvn clean install -DcustomProp=newValue

它运作良好。它将 customProp 的值更新为 newValue
但是我想用 customProp 的先前值连接 newValue。这样 customProp 的值将是 2.4.snapnewValue。 我怎样才能做到这一点?

此外,是否可以将 snap 替换为 newValue 以便 customProp 的值将是 2.4.newValue.

<properties>
  <customProp>snap</customProp>
</properties>

<version>2.4.${customProp}</version>

在你的情况下这可能吗?当然,在我使用 <version>.

的地方使用正确的标签

解决这个问题的最佳方法可能更像是:

<properties>
  <customPropPrefix>2.4.</customPropPrefix>
  <customProp>snap</customProp>
</properties>

<version>${customPropPrefix}${customProp}</version>

现在您可以同时指定 -DcustomPropPrefix=2.4.-DcustomProp=newValue

与其强行构建和清理您的 maven 项目,它肯定会更新您的 maven 项目enter image description here