Closed mruzicka closed 2 years ago
Thanks for your PR. To get a better understanding of the issue you want to tackle , could you provide a usage example?
Thank you for looking into this!
What I'm after is to be able to wedge the git branch/tag into an existing -SNAPSHOT version. Suppose I have a version like this in my pom: 1.0.0‑java7‑SNAPSHOT
and the following configuration in .mvn/maven-git-versioning-extension.xml
:
...
<ref type="branch">
<pattern>master</pattern>
</ref>
<ref type="branch">
<pattern>.+</pattern>
<version>${version.release}${version.release.label.prefixed}-${ref}${version.snapshot.label.prefixed}</version>
</ref>
...
This gives me unchanged version on the master branch, but version including the branch name wedged between the existing label (-java7
) and the possible snapshot suffix on any other branch.
E.g. on the dev
branch I get: 1.0.0‑java7‑dev‑SNAPSHOT
I don't see a way to achieve that without the placeholders I propose.
I think you could just use following version template to achieve your version.
<version>${version.release}-${ref}-SNAPSHOT</version>
instead of
<version>${version.release}${version.release.label.prefixed}-${ref}${version.snapshot.label.prefixed}</version>
No, that would lose the -java7
label and would add the -SNAPSHOT
suffix even to release versions.
could you give an example of <version>
in original pom file and expected version or the version you want to create?
I think I got your point. What about following placeholders:
assume following pom project version 1.2.3-java7-SNAPSHOT
:
version.release
-> 1.2.3-java7
remove only -SNAPSHOT
labelsversion.core
-> 1.2.3
version.label
-> java7-SNAPSHOT
version.label.release
-> java7
remove only -SNAPSHOT
labelsversion.label.release.prefixed
-> -java7
version.label.snapshot
-> SNAPSHOT
version.label.snapshot.prefixed
-> -SNAPSHOT
assume following pom project version 1.2.3-java7
:
version.release
-> 1.2.3-java7
remove only -SNAPSHOT
labelsversion.core
-> 1.2.3
version.label
-> java7
version.label.release
-> java7
remove only -SNAPSHOT
labelsversion.label.release.prefixed
-> -java7
version.label.snapshot
-> ``version.label.snapshot.prefixed
-> ``then you should be able to generate your version like this
<version>${version.release}-${ref}${version.label.snapshot.prefixed}</version>
WDYT?
However in general I think your versioning should follow semantic versioning and -...
indicates a pre-release version, so you should use versions like 1.2.4.java-SNAPSHOT
and then it works with current placeholders already.
I like your proposal. It has all the flexibility I need and by changing the ${version.release}
definition it makes it even more straightforward to achieve my goal. So If the breaking changes to ${version.release}
and ${version.label}
are not a concern, I can go ahead and update the PR accordingly.
Re semantic versioning: I did not know the pre-release build concept, thanks for bringing it to my attention. Unfortunately it does not apply in our use case. It may apply in our use case.
Re examples: Given my original template (or your template using the new semantics), my desire is to have the ${project.version} transformed as follows (on any branch except master): |
${project.version} |
git branch name | desired version |
---|---|---|---|
1.0.0‑java7‑SNAPSHOT |
dev | 1.0.0‑java7‑dev-SNAPSHOT |
|
1.0.0‑java7 |
dev | 1.0.0‑java7‑dev |
|
1.0.0‑SNAPSHOT |
dev | 1.0.0‑dev-SNAPSHOT |
|
1.0.0 |
dev | 1.0.0‑dev |
I want the ${project.version}
unmodified on the master branch, but that is taken care of by the below configuration:
...
<ref type="branch">
<pattern>master</pattern>
</ref>
...
hmm I am not that sure anymore, if this is the right approach
For edge cases like yours I think it is maybe better to introduce an optional regex <projectVersionPattern>
so you can model access to every part of your version format e.g.
<projectVersionPattern><![CDATA[^(?<core>.+?)(?<label>-SNAPSHOT)?$]]></projectVersionPattern>
<refs>
<ref type="branch">
<pattern>master</pattern>
</ref>
<ref type="branch">
<pattern>.+</pattern>
<version>${version.core}-${ref}${version.label}</version>
</ref>
</refs>
That is of course ultimately flexible and does not bloat the defined placeholders with rarely used ones. So, I agree this is the way to go. Is this something you want to look into yourself or would you prefer me taking a stab at it?
I'll will work on this next weekend
feel free to try brand new version 9.1.0
Description
Sometimes there is a need to wedge the git branch/tag information between an already present version label and possible
‑SNAPSHOT
suffix. In order to do that conveniently we'd need the label to be parsed into two parts:-SNAPSHOT
suffix-SNAPSHOT
suffixChange
This PR introduces four new version label placeholders to assist in the situation described above:
${version.release.label}
- provides the version label with the snapshot suffix removed, if there is no snapshot suffix then this placeholder is identical to the${version.label}
placeholder${version.release.label.prefixed}
- prefixed version of the${version.release.label}
placeholder${version.snapshot.label}
- provides the version's snapshot suffix or an empty string if there is no snapshot suffix${version.snapshot.label.prefixed}
- prefixed version of the${version.snapshot.label}
placeholderExamples
1.0.0‑java7‑SNAPSHOT
java7
‑java7
SNAPSHOT
‑SNAPSHOT
1.0.0‑java7
java7
‑java7
1.0.0‑SNAPSHOT
SNAPSHOT
‑SNAPSHOT
1.0.0