Search code examples
javaregexmavenbuild-helper-maven-plugin

build-helper-maven-plugin goal:regex-property how to access generated property


I try to parse version of project into new variable named build-number, i use following plugin

    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>rename-property</id>
            <goals>
                <goal>regex-property</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <name>build-number</name>
                <value>${project.version}</value>
                <regex>\.</regex>
                <replacement>_</replacement>
                <failIfNoMatch>false</failIfNoMatch>
            </configuration>
        </execution>
    </executions>
</plugin>

My properties section in pom.xml looks like this

 <modelVersion>4.0.0</modelVersion>

 <groupId>xxx.xxx.xxx</groupId>
 <artifactId>xxx</artifactId>
 <version>1.1.2</version>
 <packaging>rar</packaging>

 <properties>
     <build-number></build-number>
 </properties>

My question is how to access this variable, after launch of mvn build i can see

[INFO] --- build-helper-maven-plugin:1.7:regex-property (rename-property) @ xxx--- [INFO] Setting property 'build-number' to '1_1_2'.


Solution

  • I found out that when we set phase to validate then all works fine.