1

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'.

Stigyi
  • 31
  • 1
  • 4
  • Is there a good reason why not using `parse-version` goal? See https://www.mojohaus.org/build-helper-maven-plugin/parse-version-mojo.html and what exactly are you trying to accomplish...? – khmarbaise Aug 20 '18 at 17:22
  • i need to parse my version into new variable with dots replaced with underscore. This new variable will be used to build path. – Stigyi Aug 21 '18 at 06:37
  • This is what I can already read from your post...But why would you like to do that? And what is the purpose ? And what kind of problem are you trying to solve? Furthermore the `parse-version` goal has also a part for `osgiVersion`..? – khmarbaise Aug 21 '18 at 07:06
  • At build time i need to pass build-number to properties file as placeholder. My problem is that i don't how to get this property... I thought that build-number will be accessible at build time... like ${build-number} or/and it will be written in pom at target directory – Stigyi Aug 21 '18 at 12:45
  • Where do you need them? For what purpose? The properties can used for filtering resources ? – khmarbaise Aug 21 '18 at 16:23
  • It is a bigger project the properties file is used by install4j. Maven is passing the variables by resources filtering to the file. But this is not clue of a problem. The clue is that i have no idea how to access build-number property. When it's not set, maven is not recognizing it, and in properties file after build in target i can see ${build-number}, When property is set to empty it is generating empty target.When property is set for example to "1" in target we can see "1" etc. the maven log is showing us that property is set, but where is it ? – Stigyi Aug 21 '18 at 18:29

1 Answers1

2

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

Stigyi
  • 31
  • 1
  • 4
  • 1
    You need to set that because that goal isn't bound to any phase by default. You could actually use any phase provided that it happens before the property is used. – toolforger Jan 24 '19 at 08:33