简体   繁体   English

maven pom.xml 将版本写入文件

[英]maven pom.xml write version to file

Assume we have this pom.xml detail, when we run mvn clean verify , we are able to retrieve the version "0.0.1-snapshot" from "${project.version}" tag and write to a file, however the file shows ending "%" for example 0.0.1-SNAPSHOT% .假设我们有这个 pom.xml 细节,当我们运行mvn clean verify时,我们能够从“${project.version}”标签中检索版本“0.0.1-snapshot”并写入文件,但是文件显示以“%”结尾,例如0.0.1-SNAPSHOT% How do we remove ending "%".我们如何删除结尾的“%”。 Been using maven-antrun-plugin.一直在使用 maven-antrun-plugin。

<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>
<groupId>com.mp</groupId>
<artifactId>parentApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parentApp</name>
<description>This is just to test pom inheritance</description>


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <defaultGoal>package</defaultGoal>
    <plugins>
      <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>echodir</id>
            <goals>
                <goal>run</goal>
            </goals>
            <phase>verify</phase>
            <inherited>true</inherited>
            <configuration>
                <target>
                <echo file="log-ant-run.txt" append="false" message="${project.version}"/>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-core</artifactId>
            <version>5.1.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
    </dependencies>
</dependencyManagement>
</project>

Result:结果:

example % cat log-ant-run.txt
0.0.1-SNAPSHOT%                                                                                                                                                                                                                                                      

That is how MacOS "highlights" the absence of CR/LF in file:这就是 MacOS 如何“突出显示”文件中缺少 CR/LF 的方式:

 ~ % echo -ne test > test.txt
 ~ % cat test.txt
test%
 ~ %

but:但:

 ~ % echo test > test.txt 
 ~ % cat test.txt        
test
 ~ % 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM