0

I'm using the Build Helper Maven Plugin with the regex-property goal. I want to remove any qualifiers from a version, giving me a project.releaseVersion property.

Let's say my project is using version 1.2.3-SNAPSHOT. I can use the following:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    <execution>
      <id>set-project-release-version</id>
      <goals>
        <goal>regex-property</goal>
      </goals>
      <configuration>
        <name>project.releaseVersion</name>
        <value>${project.version}</value>
        <regex>-SNAPSHOT</regex>
        <failIfNoMatch>false</failIfNoMatch>
      </configuration>
    </execution>
  </executions>
</plugin>

Sure enough, now project.releaseVersion now contains 1.2.3. Nice.

Unfortunately this doesn't work with other non-release versions, such as 1.2.3-beta.4. So to get the "release" version, I simply want to remove everything after the first -. In regular expression form, I should be able to match -* and replace it with nothing, removing the dash and everything after it, just like I did for -SNAPSHOT. So I tried this:

        <regex>-*</regex>

If I try that on 1.2.3-SNAPSHOT, it gives me 1.2.3SNAPSHOT. It appears to match the regular expression, but only replaces the -, not the entire match.

Is this a bug, as it seems to be, or am I doing it wrong? And does anybody know a workaround?

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • 1
    You are familiar with regular expressions? `-*` is not correct cause it will not match `1.2.3-SNAPSHOT`...apart from that `1.2.3-beta.4` is a release version. I would suggest to try something this. `-SNAPSHOT` furthermore the question is: Why do you need that? I have checked the output via `-X` it works as expected? If you like to have the `1.2.3` of `1.2.3-beta.4` you have to use `-.*` instead... – khmarbaise Dec 17 '18 at 17:58
  • Yes, I am familiar with regular expressions. I think I must have had a brain hiccup, because I was thinking in glob mode. I'll try `-.*` and see how that works. – Garret Wilson Dec 18 '18 at 00:17
  • @khmarbaise, Can you provide me a reference that `1.2.3-beta.4` is a release version? According to [Semantic Versioning](https://semver.org/) (which is what I'm trying to follow), any version with a hyphen and things following it is considered a "pre-release" version: "A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version." – Garret Wilson Dec 18 '18 at 00:34
  • @khmarbaise that indeed fixed my problem; I needed to use the regex `-.*` instead of the glob-like expression `-*`. Would you like to provide that in an answer so that I can mark it as correct? Otherwise, I'll provide a separate answer myself, but you're the one who pointed it out. – Garret Wilson Dec 18 '18 at 00:43
  • Actually I'm thinking of just deleting this question. As it was predicated on a blatant mistake (brain hiccup not withstanding), it may just provide more clutter than help. – Garret Wilson Dec 18 '18 at 01:15

0 Answers0