Friday, 19 January 2024

Maven Version Versions and a Regex Block Refactoring of Sequential Identifier

In the first post in this series I had thought about the need for a globally unique incrementable artifect id, in the next post I not only designed but tested a proposal for such a globally unique artifact id and how to change it.

A triumph of thought and testing over trial and error.

So I tried using the new scheme with the Maven Release Plugin.

A depressing journey into the rabbit hole that is Apache, Maven and the Release Plugin, a crucial tool in our pipeline.

It turns out that whilst the Maven Artifact Version I had tested against allowed my new scheme the Release Plugin has its own subset of such versions which are gate-kept by a Regular Expression.

          "^((?:\\d+\\.)*\\d+)" // digit(s) and '.' repeated followed by digit (version digits 1.22.0, etc)
                    + "([-_])?" // optional - or _ (annotation separator)
                    + "([a-zA-Z]*)" // alpha characters (looking for annotation - alpha, beta, RC, etc.)
                    + "([-_])?" // optional - or _ (annotation revision separator)
                    + "(\\d*)" // digits (any digits after rc or beta is an annotation revision)
                    + "(?:([-_])?(.*?))?$"); // - or _ followed everything else (build specifier)

This stops any version which does not start with digits and full stops from being recognised as a version.

Current Incremented Outcome
VTW360-2023-1.0.3-SNAPSHOT Unable to parse the version string F
VTW360.2023.1.0.4-SNAPSHOT Unable to parse the version string F
VTW360-2023.1.0.4-SNAPSHOT Unable to parse the version string F
VTW-360-2023.1.0.14-SNAPSHOT Unable to parse the version string F
VTW-360.2023.1.0.16-SNAPSHOT Unable to parse the version string F
2023-VTW360-1.0.3-SNAPSHOT 2023-VTW361-1.0.4-SNAPSHOT Eh?
2023|VTW-360|1.0.14 Illegal characters in jar name F
2023#VTW-360#1.0.14-SNAPSHOT 2024#VTW-360#1.0.14-SNAPSHOT Eh?
2023.VTW-360.1.0.14-SNAPSHOT 2024.VTW-360.1.0.14-SNAPSHOT Eh?
360.2023-1.0.15-SNAPSHOT 360.2023-2.0.15-SNAPSHOT Eh?
2023.360.1.0.14-SNAPSHOT 2023.360.1.0.15-SNAPSHOT Meh
1.0.19-VTW360-2023.SNAPSHOT hangs Eh?
1.0.19-VTW360-2023-SNAPSHOT 1.0.19-VTW361-2023-SNAPSHOT Eh?
1.0.19-2023-VTW360-SNAPSHOT 1.0.19-2024-VTW360-SNAPSHOT Eh?
1.0.19-YY24-VTW360-SNAPSHOT 1.0.19-YY25-VTW360-SNAPSHOT F
1-0-19-2025-VTW360-SNAPSHOT 1-1-19-2025-VTW360-SNAPSHOT Eh?
360.2023.1.0.16-SNAPSHOT 360.2023.1.0.17-SNAPSHOT MKay

Proposal 3

So we are forced to allocate meaning to digits and place, never a good idea, but it is that or try and change the behaviour of the Release Plugin, a task I do not think I have the time or the energy for.

\dcode for project
\d\d\dcode for repository
\d\d\d\dyear
\d+Major
\d+Minor
\d+Patch

I added the new proposal to the tests, and wrote some more tests based upon the above regex.

We land with 2.130.2024.2.0.6.

However much you think about the problem previous engineers will have constrained your choices.

No comments:

Post a Comment