Properties Maven使用$${…}作为文本而不是实际属性值不起作用
我有一个pom.xml,使用ant run插件,我试图替换pom.xml中的以下内容:Properties Maven使用$${…}作为文本而不是实际属性值不起作用,properties,maven-3,literals,Properties,Maven 3,Literals,我有一个pom.xml,使用ant run插件,我试图替换pom.xml中的以下内容: From: <version>${current.build.version}</version> To: <version>DEV.0.0-SNAPSHOT</version> 来自: ${current.build.version} 致: DEV.0.0-SNAPSHOT 我用GoogleReplacer插件和maven ant ru
From:
<version>${current.build.version}</version>
To:
<version>DEV.0.0-SNAPSHOT</version>
来自:
${current.build.version}
致:
DEV.0.0-SNAPSHOT
我用GoogleReplacer插件和maven ant run插件做了同样的尝试,这两个插件都解析为属性的实际值,而不是文本
完整的POM.xml如下所示
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>x.y.z</groupId>
<artifactId>parent</artifactId>
<version>${current.build.version}</version>
</parent>
<properties>
<!-- Build Version for Entire Stream -->
<current.build.version>DEV.0.0-SNAPSHOT</current.build.version>
<!-- Replacement property while installing poms for child projects -->
<parent.version.property.name>current.build.version</parent.version.property.name>
</properties>
<artifactId>child</artifactId>
<version>${current.build.version}</version>
<packaging>jar</packaging>
<build>
<plugins>
<!-- Replace parent version from property to actual version just before install -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<!-- Replace parent version if its a property to respective version -->
<execution>
<id>replace-parent-property-to-version</id>
<phase>post-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<exportAntProperties>true</exportAntProperties>
<target name="replace-parent-property-to-version">
<!-- Get some Ant-Contrib task def -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath refid="maven.plugin.classpath" />
</taskdef>
<!-- Copy original file to temp location first -->
<var name="orig.project.file" value="${basedir}/pom.xml" />
<var name="temp.project.file.name" value="versioned-pom.xml" />
<var name="temp.project.file" value="${project.build.directory}/${temp.project.file.name}" />
<copy file="${orig.project.file}" tofile="${temp.project.file}" />
<!-- Replace the parent version from property to actual value -->
<var name="dollar" value="$${" />
<var name="curlBrace" value="}" />
<var name="var.parent.version.property.name" value="${dollar}${parent.version.property.name}${curlBrace}" />
<replace file="${temp.project.file}" token="<version>${var.parent.version.property.name}</version>"
value="<version>${project.version}</version>" />
<!-- Now overwrite project file property with update temp file for release -->
<var name="project.file" unset="true" />
<property name="project.file" value="${temp.project.file}" />
<echo message="Parent version updated for release in file ${project.file}..." />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
整数解
父母亲
${current.build.version}
DEV.0.0-SNAPSHOT
当前.build.version
小孩
${current.build.version}
罐子
org.apache.maven.plugins
maven antrun插件
将父属性替换为版本
整合后测试
跑
真的
如果您看到我的配置,我已经$$
,它也会解析为属性值,而不是${…}
。我无法解决这个问题
还有一个maven格式的属性,我可以访问pom.xml文件位置。我在文档中找到了它名为
project.file
,但我无法在ant run插件中访问它。它说不设置。你不应该这样做,这是一种反模式。我相信您在尝试构建时已经看到了Maven的警告
这样做可能很有诱惑力,但它会导致不可重复的构建,因此不鼓励这样做。相反,您应该始终在那个里保留一个文本(例如“DEV.1.0-SNAPSHOT”)值,并使用更新其值
如果整个项目只有一个版本,并且父版本兼作模块pom(另一个常见但可容忍的反模式),则可以在其pom中声明父版本,在任何子版本的父部分中再次声明父版本,并跳过子版本。你这样执行
mvn versions:set -DnewVersion=DEV.1.0
在模块项目上发布
你提交,发布,然后执行
mvn versions:set -DnewVersion=DEV.1.1-SNAPSHOT
要恢复开发,…也许你应该试试……看起来很有希望,但我试过了,但似乎没有任何效果。…你使用哪个Maven版本?Maven 3.3.x。我不限于此…我可以使用任何最新版本..如果您使用例如
${revision}
在版本标签上,您可以简单地执行mvn-Drevision=1.2.3-DEV clean package
,而无需对antrun等有特殊需求。这是Maven的一部分。我知道,但可以想象,我们需要调整此系统以发布每月版本……更改所有这些文件,然后将其提交给源代码控制无法可靠地自动化。我说的是每个月100多个部件!这是不可伸缩的,您只需为父级/聚合器执行一次命令。版本插件本身然后将更改传播到所有其他模块。如果使用git,只需在发布分支上执行,提交,执行发布(部署等),然后增加到下一个快照版本并再次提交。然后合并回主开发分支。它可以很容易地包装在一个简单的工作(或加强管道),并有詹金斯在它。