Automatic Versioning
The version-cli-core module provides Git-based version resolution, deriving versions from repository state and commit messages.
libraryDependencies += "africa.shuwari" %% /* or `%%%` */ "version-cli-core" % "0.6.2"
Note: JVM and Native Platforms only at this point in time.
How It Works
The resolution engine analyses:
- Git tags — annotated version tags define release boundaries
- Commit messages — directives like
breaking:ortarget: 2.0.0 - Working directory — clean vs dirty state
And produces one of:
| Mode | Condition | Result |
|---|---|---|
| Concrete | Clean worktree at annotated tag | Exact tag version |
| Development | Any other state | Snapshot with metadata |
Quick Example
import version.cli.core.*
import version.cli.core.domain.*
val config = CliConfig(
repo = os.pwd,
basisCommit = "HEAD",
prNumber = None,
branchOverride = None,
shaLength = 7,
verbose = false
)
VersionCliCore.resolve(config) match
case Right(version) =>
println(s"Version: $version")
case Left(error) =>
println(s"Error: ${error.message}")
Development Versions
When not at a clean tag, the engine produces:
<TARGET>-SNAPSHOT+<METADATA>
Where metadata includes:
| Identifier | Example | Purpose |
|---|---|---|
pr<N> |
pr42 |
Pull request number |
branch<name> |
branchmain |
Current branch |
commits<N> |
commits5 |
Commits since tag |
sha<hex> |
shaabc1234 |
Commit SHA |
dirty |
dirty |
Uncommitted changes |
Example: 1.2.4-SNAPSHOT+pr42.branchmain.commits5.shaabc1234.dirty
See also
- How It Works — detailed resolution flow
- Commit Directives — controlling versions via commits
- Validation Rules — target directive validation
In this article