jmongard / Git.SemVersioning.Gradle

Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages.
https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin
Apache License 2.0
38 stars 4 forks source link

Move `-SNAPSHOT` to the end when it's part of the version string #30

Closed tacascer closed 9 months ago

tacascer commented 9 months ago

Hi there,

Maven repositories usually require that a snapshot version end in -SNAPSHOT. Is it possible to move -SNAPSHOT to the end of the version string if it is included in the string?

jmongard commented 9 months ago

Snapshot is already added at the end?

$ ./gradlew printVersion
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :printVersion
11.11.5-SNAPSHOT
tacascer commented 9 months ago

Oh I meant when doing infoVersion and semVersion

sschuberth commented 9 months ago

I guess turning something like 1.1.0-SNAPSHOT+052 into 1.1.0+052-SNAPSHOT would violate SemVer syntax:

<version core> "-" <pre-release> "+" <build>
tacascer commented 9 months ago

Yeah that is true Unfortunately Maven version convention doesn't fully conform to semver Maybe we can add a toggle for a "Maven style version" where the -SNAPSHOT will be at the end?

jmongard commented 9 months ago

The change for putting version at the end would only be needed when used by maven publish? So I guess you could do (in kotlin):

publishing {
    repositories {
        maven {
            url = ...
        }
    }
    publications {
        create<MavenPublication>("my publication") {
            version = semver.semVersion.toString().replace(Regex("^(.*?)(-SNAPSHOT)(.*)$"), "$1$3$2")
        }
    }
}

adding a flag the toInfoVersionString is possible I guess but I'm not sure how common it is to include commitcount and sha in published snapshots. I guess the publication would be done like above but instead

version = semver.semVersion.toInfoVersionString(preReleaseLast=true)
tacascer commented 9 months ago
publishing {
    repositories {
        maven {
            url = ...
        }
    }
    publications {
        create<MavenPublication>("my publication") {
            version = semver.semVersion.toString().replace(Regex("^(.*?)(-SNAPSHOT)(.*)$"), "$1$3$2")
        }
    }
}

Oh that looks like a cool solution

The use case is common enough in our organization. We are publishing snapshots each PR, and those PRs would resolve to the same version if doing printVersion. This leads to people not being able to uniquely identify their PRs, so some extra metadata would be helpful.

version = semver.semVersion.toInfoVersionString(preReleaseLast=true)

How do you feel about adding that flag?

jmongard commented 9 months ago

I guess forcing developers to fully comply with semver is not a goal for this plugin so I added a appendPreReleaseLast parameter to toInfoVersionString in version 0.7.0.

version = semver.semVersion.toInfoVersionString(shaLength = 7, appendPreReleaseLast = true)
tacascer commented 9 months ago

This looks awesome! Thanks so much.