Skip to content

Commit 953ee59

Browse files
authored
feat: add versioning (#490)
Signed-off-by: Bartosz Czyż <czyzbartosz3@gmail.com>
1 parent 5e9eae6 commit 953ee59

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

here-naksha-cli/build.gradle.kts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ plugins {
66
}
77

88
description = gatherDescription()
9+
version = "0.1.0"
910
val mainCliClass = "com.here.naksha.cli.Main"
1011
val fatJarBaseName = "naksha-cli"
12+
val versionFile = project.projectDir.resolve("src/jvmMain/java/com/here/naksha/cli/VersionInfo.java")
1113

1214
configurations.all {
1315
exclude(group = "org.slf4j", module = "slf4j-simple")
@@ -51,20 +53,40 @@ tasks {
5153
}
5254

5355
val shadowCreate by registering(ShadowJar::class) {
56+
group = "Shadow"
57+
description = "Creates fat jar"
5458
archiveBaseName.set(fatJarBaseName)
5559
archiveClassifier.set("")
56-
archiveVersion.set(project.version.toString())
60+
archiveVersion.set(version.toString())
5761
manifest {
5862
attributes["Main-Class"] = mainCliClass
5963
}
60-
6164
from(kotlin.jvm().compilations.getByName("main").output)
62-
6365
configurations = listOf(project.configurations.getByName("jvmRuntimeClasspath"))
6466
}
6567

66-
named("jvmJar") {
67-
dependsOn(shadowCreate)
68+
val generateVersionFile by registering {
69+
doLast {
70+
if (!versionFile.exists()) throw GradleException("${versionFile.name} file not found: ${versionFile.path}")
71+
versionFile.writeText(
72+
"""
73+
package com.here.naksha.cli;
74+
import picocli.CommandLine;
75+
// This file is auto-generated by Gradle. ANY CHANGE WILL BE OVERWRITTEN!
76+
public final class VersionInfo implements CommandLine.IVersionProvider {
77+
@Override
78+
public String[] getVersion() {
79+
return new String[] {"$fatJarBaseName $version"};
80+
}
81+
private VersionInfo() {}
82+
}
83+
""".trimIndent()
84+
)
85+
}
86+
}
87+
88+
getByName("jvmMainClasses") {
89+
dependsOn(generateVersionFile)
6890
}
6991
}
7092

here-naksha-cli/naksha-cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e # exit on error
33

44
DIR="$(cd "$(dirname "$0")" && pwd)"
5-
gradle :here-naksha-cli:jvmJar > /dev/null 2>&1
5+
gradle :here-naksha-cli:shadowCreate > /dev/null 2>&1
66

77
JAR=$(find "${DIR}/build/libs" -name "naksha-cli*.jar" -type f -exec ls -t {} + | head -n 1)
88

here-naksha-cli/src/jvmMain/java/com/here/naksha/cli/NakshaCliCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
mixinStandardHelpOptions = true,
1010
subcommands = {
1111
CopyCommand.class
12-
}
12+
},
13+
versionProvider = VersionInfo.class
1314
)
1415
public final class NakshaCliCommand {
1516
@CommandLine.Mixin
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.here.naksha.cli;
2+
import picocli.CommandLine;
3+
// This file is auto-generated by Gradle. ANY CHANGE WILL BE OVERWRITTEN!
4+
public final class VersionInfo implements CommandLine.IVersionProvider {
5+
@Override
6+
public String[] getVersion() {
7+
return new String[] {"naksha-cli 0.1.0"};
8+
}
9+
private VersionInfo() {}
10+
}

0 commit comments

Comments
 (0)