简体   繁体   中英

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% . How do we remove ending "%". Been using 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:

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

but:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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