Skip to content

Add branch suffix for snapshots onlyย #969

@DavidGofferje

Description

@DavidGofferje

I really like behavior of versionCreator 'versionWithBranch', except for one thing.
I want it to work for snapshots only.
E.g. on branch hotfix I want currentVersion return:

1.0.1 when on release tag, current behavior is 1.0.1-hotfix
1.0.2-hotfix-SNAPSHOT otherwise

This was mentioned (and closed) before in Issue #269 because the Creator interface didn't facilitate this behaviour.

I've made a fix for this, by introducing a new interface specifically for a version Creator in VersionProperties.java
public interface VersionCreator { String apply(String versionFromTag, ScmPosition position, VersionContext versionContext); }

This allowed me to create a new predefined version creator specifically for this need:
VERSION_WITH_BRANCH_WHEN_SNAPSHOT('versionWithBranchWhenSnapshot', { String versionFromTag, ScmPosition position, VersionContext versionContext -> if ((versionContext.position.branch != 'master' && versionContext.position.branch != 'main') && versionContext.position.branch != 'HEAD' && versionContext.isSnapshot()) { return "$versionFromTag-$versionContext.position.branch".toString() } return versionFromTag }),

Of course, I refactored all predefined version creators (and their tests) to be adhere to this new interface. It is, however, of course not backwards compatible with custom made version creators, as it needs an extra parameter. The change needed is however, very minor, like this:
{version, position -> ...}
to
{version, position, context -> ...}

where the context param can be ignored for existing creators.

I've attached my fix to this post. It does not contain new tests, but the existing ones are respected. Of course I will, should you approve my fix, provide test cases as well.

Please consider this extra functionality.

axion-release-plugin.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions