Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifact of tag gets "-SNAPSHOT" added #229

Closed
dermoritz opened this issue Jan 10, 2023 · 6 comments
Closed

Artifact of tag gets "-SNAPSHOT" added #229

dermoritz opened this issue Jan 10, 2023 · 6 comments
Assignees
Labels

Comments

@dermoritz
Copy link

I am glad that i found this "plugin" it is in fact my first "extension". More or less i copied from example without understanding.
What i want at the end is to reproduce the normal Maven way for versioning artifacts (mvn deploy goal):
master

  • on master every artifacts version is <last (version) tag>-SNAPSHOT
  • the artifact version build from tag is just
    branches
  • artifact version is -SNAPSHOT

This is my current setup:

<configuration xmlns="https://github.com/qoomon/maven-git-versioning-extension"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="https://github.com/qoomon/maven-git-versioning-extension https://qoomon.github.io/maven-git-versioning-extension/configuration-9.1.0.xsd">

    <refs>
        <ref type="branch">
            <pattern>.+</pattern>
            <version>${ref}-SNAPSHOT</version>
            <properties>
                <foo>${ref}</foo>
            </properties>
        </ref>

        <ref type="tag">
            <pattern><![CDATA[v(?<version>.*)]]></pattern>
            <version>${ref.version}</version>
        </ref>
    </refs>

    <!-- optional fallback configuration in case of no matching ref configuration-->
    <rev>
        <version>${commit}</version>
    </rev>

</configuration>

and for branches sadly including master it is working (master-SNAPSHOT).
But everything gets -SNAPSHOT added i tried with tag "0.1.0" and "v0.1.0". How to adopt the configuration to fulfill my requirements?

Thanks in advance

@qoomon qoomon self-assigned this Jan 11, 2023
@qoomon
Copy link
Owner

qoomon commented Jan 11, 2023

Hi @dermoritz, I'm sorry but I don't get what versioning pattern you want to achieve. Could you give some samples.

@dermoritz
Copy link
Author

Sorry i was not very clear and even made a mistake.4

On Master

If there is no tag yet: the version should be -SNAPSHOT
So i would define a value like "0.0.1" and as long there is no tag the version is always 0.0.1-SNAPSHOT

If i tag the version: of tagged commit and artifact should be e.g. my first tag would be "0.0.1" then version is also "0.0.1

Commits on master after a Tag: -SNAPSHOT. So if the last tag on master is 0.0.1 i need to define to add something (not sure if possible). But for example i want always increase the last digit like "x.y.+1" the version should be "0.0.2-SNAPSHOT".
In this case if the last tag is 1.1.0 the version would be 1.1.1-SNAPSHOT (last digit increased by 1)

In classic versioning you can define "next release" somewhere or how to derive next release from the current release - how is this possible here?

Branches

Version should always be -SNAPSHOT

@qoomon
Copy link
Owner

qoomon commented Jan 11, 2023

Your config will behaves as follows:

  • if you are on any branch (git branch output is * master)
    • the version pattern will be ${ref}-SNAPSHOT e.g. master-SNAPSHOT or feature-fly-to-the-moon-SNAPSHOT
  • if you are in a detached mode (git branch output is * (HEAD detached at 1234567)) and a version tag (v1.0.0) is pointing to the current commit ( git tag --points-at output is v1.0.0)
    • the version pattern will be ${ref.version} e.g. 1.0.0 if the tag is v1.0.0

if you want to versioning by tag even if you are on a branch (git branch output is * master) you need to use the option <refs considerTagsOnBranches="true">. you also need to move <tag> configuration above the <branch> configuration, because the first matching configuration will be used. e.g.

<configuration xmlns="https://github.com/qoomon/maven-git-versioning-extension"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="https://github.com/qoomon/maven-git-versioning-extension https://qoomon.github.io/maven-git-versioning-extension/configuration-9.1.0.xsd">

    <refs considerTagsOnBranches="true">

       <ref type="tag">
            <pattern><![CDATA[v(?<version>.*)]]></pattern>
            <version>${ref.version}</version>
        </ref>

        <ref type="branch">
            <pattern>.+</pattern>
            <version>${ref}-SNAPSHOT</version>
        </ref>

    </refs>

    <!-- optional fallback configuration in case of no matching ref configuration-->
    <rev>
        <version>${commit}</version>
    </rev>

</configuration>

if you want to use the latest release tag version for your branch versions you need to use a branch config like this:

        <ref type="branch">
            <pattern>.+</pattern>
            <version>${describe.tag.version.core}-SNAPSHOT</version>
            <describeTagPattern>v[0-9].+</describeTagPattern>
        </ref>

@qoomon
Copy link
Owner

qoomon commented Jan 11, 2023

@dermoritz have a look at the [README.md] and search for describe.tag.version.patch.next or even describe.tag.version.patch.next.plus.describe.distance

then you could create a <version> pattern like ${describe.tag.version.major}.${describe.tag.version.minor}.${describe.tag.version.patch.next} or just ${describe.tag.version.core}.${describe.distance}

however I would suggest something like ${describe.tag.version.core}-${ref}-SNAPSHOT, because if you don't use the ref part it could lead to ambiguous versions if you work on multiple branches

@dermoritz
Copy link
Author

Thanks @qoomon for your detailed answers. in regards of ambiguous version for SNAPSHOT - this is the desired behavior for "SNAPSHOT". it is never stable.
Is there a way to see the version without "deploying" or "installing" the artifact? Testing trying would be faster if i could just run the extension and see the version it creates.

I will try you suggestions anyway.

@qoomon
Copy link
Owner

qoomon commented Jan 13, 2023

Regarding the snapshot builds you are totally right however you want to be able to distinguish between branch A snapshots and branch B snapshots therefore your should include the ${ref} placeholder. The ref placeholder is the branch name.

To get the version you could simply run

  • mvn validate
  • or mvn help:evaluate -Dexpression=project.version
  • or mvn help:evaluate -Dexpression=project.version -q -DforceStdout if you want to use version in a shell script

also see README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants