From d970c968a63043a43c813ba3879337e53d78db2c Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Wed, 13 Sep 2023 11:19:45 +0200 Subject: [PATCH 1/4] feature: Publish Kuksa SDK Snapshot Builds to MavenLocal Closes: #6 Signed-Off-By: Andre Weber --- buildSrc/src/main/kotlin/publish.gradle.kts | 35 +++++++++++++++++++++ kuksa-sdk/build.gradle.kts | 6 +++- settings.gradle.kts | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 buildSrc/src/main/kotlin/publish.gradle.kts diff --git a/buildSrc/src/main/kotlin/publish.gradle.kts b/buildSrc/src/main/kotlin/publish.gradle.kts new file mode 100644 index 00000000..776b21c9 --- /dev/null +++ b/buildSrc/src/main/kotlin/publish.gradle.kts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * + */ + +plugins { + `maven-publish` +} + +afterEvaluate { + publishing { + repositories { + // to be defined + } + publications { + register("release") { + from(components["release"]) + } + } + } +} diff --git a/kuksa-sdk/build.gradle.kts b/kuksa-sdk/build.gradle.kts index 2b5d0b87..13422c0f 100644 --- a/kuksa-sdk/build.gradle.kts +++ b/kuksa-sdk/build.gradle.kts @@ -5,10 +5,14 @@ plugins { id("org.jetbrains.kotlin.android") id("com.google.protobuf") + publish } +group = "org.eclipse.kuksa" +version = "0.1.0-SNAPSHOT" + android { - namespace = "com.etas.kuksa.sdk" + namespace = "org.eclipse.kuksa" compileSdk = 33 defaultConfig { diff --git a/settings.gradle.kts b/settings.gradle.kts index 6dc6cc16..97455c8f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,6 +9,7 @@ pluginManagement { dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { + mavenLocal() google() mavenCentral() } From f83fd55abd09e658c0b498d5f9e8b1a9ed3b925c Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 14 Sep 2023 09:08:11 +0200 Subject: [PATCH 2/4] feature: Add Centralized Versioning The version is centrally stored inside the $rootDir/version.properties. The version can be controlled purely with gradle. Therefore the following Gradle tasks were added in the "version" group of the rootProject: - increaseMajorVersion - increaseMinorVersion - increasePatchVersion - printVersion - printVersionCode - setReleaseVersion - setSnapshotVersion --- app/build.gradle.kts | 4 +- build.gradle.kts | 1 + buildSrc/src/main/kotlin/detekt.gradle.kts | 3 +- .../kuksa/extension}/ProjectExtensions.kt | 2 + .../eclipse/kuksa/util/VersionProperties.kt | 102 ++++++++++++++++++ buildSrc/src/main/kotlin/version.gradle.kts | 65 +++++++++++ kuksa-sdk/build.gradle.kts | 2 +- version.properties | 6 ++ 8 files changed, 180 insertions(+), 5 deletions(-) rename buildSrc/src/main/kotlin/{ => org/eclipse/kuksa/extension}/ProjectExtensions.kt (97%) create mode 100644 buildSrc/src/main/kotlin/org/eclipse/kuksa/util/VersionProperties.kt create mode 100644 buildSrc/src/main/kotlin/version.gradle.kts create mode 100644 version.properties diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e92268c9..7352e632 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -26,8 +26,8 @@ android { applicationId = "org.eclipse.kuksa.testapp" minSdk = 27 targetSdk = 34 - versionCode = 1 - versionName = "1.0" + versionCode = rootProject.extra["projectVersionCode"].toString().toInt() + versionName = rootProject.extra["projectVersion"].toString() vectorDrawables { useSupportLibrary = true } diff --git a/build.gradle.kts b/build.gradle.kts index 7801bd24..54d891cd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.incremental.createDirectory plugins { base detekt + version } subprojects { diff --git a/buildSrc/src/main/kotlin/detekt.gradle.kts b/buildSrc/src/main/kotlin/detekt.gradle.kts index 9447187f..0c52bece 100644 --- a/buildSrc/src/main/kotlin/detekt.gradle.kts +++ b/buildSrc/src/main/kotlin/detekt.gradle.kts @@ -1,7 +1,6 @@ import io.gitlab.arturbosch.detekt.Detekt import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask -import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.withType +import org.eclipse.kuksa.extension.lib val baselineFile = project.file("$rootDir/config/detekt/baseline.xml") diff --git a/buildSrc/src/main/kotlin/ProjectExtensions.kt b/buildSrc/src/main/kotlin/org/eclipse/kuksa/extension/ProjectExtensions.kt similarity index 97% rename from buildSrc/src/main/kotlin/ProjectExtensions.kt rename to buildSrc/src/main/kotlin/org/eclipse/kuksa/extension/ProjectExtensions.kt index 4d5601e6..5300ea08 100644 --- a/buildSrc/src/main/kotlin/ProjectExtensions.kt +++ b/buildSrc/src/main/kotlin/org/eclipse/kuksa/extension/ProjectExtensions.kt @@ -17,6 +17,8 @@ * */ +package org.eclipse.kuksa.extension + import org.gradle.api.Project import org.gradle.api.artifacts.MinimalExternalModuleDependency import org.gradle.api.artifacts.VersionCatalogsExtension diff --git a/buildSrc/src/main/kotlin/org/eclipse/kuksa/util/VersionProperties.kt b/buildSrc/src/main/kotlin/org/eclipse/kuksa/util/VersionProperties.kt new file mode 100644 index 00000000..5ff737a7 --- /dev/null +++ b/buildSrc/src/main/kotlin/org/eclipse/kuksa/util/VersionProperties.kt @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * + */ + +package org.eclipse.kuksa.util + +import java.io.File +import java.io.FileWriter +import java.io.IOException +import java.util.Locale +import java.util.Properties + +class VersionProperties(private val filePath: String) { + private val properties: Properties = Properties() + + var major: Int + get() = properties.getProperty(KEY_MAJOR).toInt() + set(value) { + properties.put(KEY_MAJOR, value.toString()) + } + + var minor: Int + get() = properties.getProperty(KEY_MINOR).toInt() + set(value) { + properties.put(KEY_MINOR, value.toString()) + } + + var patch: Int + get() = properties.getProperty(KEY_PATCH).toInt() + set(value) { + properties.put(KEY_PATCH, value.toString()) + } + + var suffix: String + get() = properties.getProperty(KEY_SUFFIX) + set(value) { + properties.put(KEY_SUFFIX, value) + } + + val version: String + get() { + var version = "$major.$minor.$patch" + if (suffix.isNotEmpty()) { + version += "-$suffix" + } + return version + } + + val versionCode: Int + get() { + val decorator = "10" + val paddedMajorVersion = String.format(Locale.ROOT, "%02d", major) + val paddedMinorVersion = String.format(Locale.ROOT, "%02d", minor) + val paddedPatchVersion = String.format(Locale.ROOT, "%02d", patch) + + return "$decorator$paddedMajorVersion$paddedMinorVersion$paddedPatchVersion".toInt() + } + + fun load() { + try { + val file = File(filePath) + val inputStream = file.inputStream() + + properties.load(inputStream) + } catch (e: IOException) { + System.err.println("Could not load file $filePath: ${e.message}") + } + } + + fun store() { + try { + val file = File(filePath) + val fileWriter = FileWriter(file) + + properties.store(fileWriter, "Generated by 'store' in VersionProperties.kt") + } catch (e: IOException) { + System.err.print("Could not write file $filePath: ${e.message}") + } + } + + private companion object { + private const val KEY_MAJOR = "MAJOR" + private const val KEY_MINOR = "MINOR" + private const val KEY_PATCH = "PATCH" + private const val KEY_SUFFIX = "SUFFIX" + } +} diff --git a/buildSrc/src/main/kotlin/version.gradle.kts b/buildSrc/src/main/kotlin/version.gradle.kts new file mode 100644 index 00000000..af69c2aa --- /dev/null +++ b/buildSrc/src/main/kotlin/version.gradle.kts @@ -0,0 +1,65 @@ +import org.eclipse.kuksa.util.VersionProperties + +val properties = VersionProperties("$rootDir/version.properties") +properties.load() + +rootProject.extra["projectVersion"] = properties.version +rootProject.extra["projectVersionCode"] = properties.versionCode + +tasks.register("increaseMajorVersion") { + group = "version" + doLast { + properties.major += 1 + properties.store() + } +} + +tasks.register("increaseMinorVersion") { + group = "version" + doLast { + properties.minor += 1 + properties.store() + } +} + +tasks.register("increasePatchVersion") { + group = "version" + doLast { + properties.patch += 1 + properties.store() + } +} + +tasks.register("setReleaseVersion") { + group = "version" + doLast { + properties.suffix = "" + properties.store() + } +} + +tasks.register("setSnapshotVersion") { + group = "version" + doLast { + properties.suffix = "SNAPSHOT" + properties.store() + } +} + +tasks.register("printVersion") { + group = "version" + doLast { + val version = properties.version + + println("VERSION=$version") + } +} + +tasks.register("printVersionCode") { + group = "version" + doLast { + val versionCode = properties.versionCode + + println("VERSION_CODE=$versionCode") + } +} diff --git a/kuksa-sdk/build.gradle.kts b/kuksa-sdk/build.gradle.kts index 13422c0f..8579b27f 100644 --- a/kuksa-sdk/build.gradle.kts +++ b/kuksa-sdk/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "org.eclipse.kuksa" -version = "0.1.0-SNAPSHOT" +version = rootProject.extra["projectVersion"].toString() android { namespace = "org.eclipse.kuksa" diff --git a/version.properties b/version.properties new file mode 100644 index 00000000..249cc253 --- /dev/null +++ b/version.properties @@ -0,0 +1,6 @@ +#Generated by 'storeVersionProperties' in version.gradle.kts +#Thu Sep 14 08:52:28 CEST 2023 +MAJOR=0 +MINOR=1 +PATCH=0 +SUFFIX=SNAPSHOT From 77792ad1b93cb34db39e1557d2c81b13b255298b Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Mon, 9 Oct 2023 07:22:44 +0200 Subject: [PATCH 3/4] chore: Reset Version to 0 on Version Increase --- buildSrc/src/main/kotlin/version.gradle.kts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/buildSrc/src/main/kotlin/version.gradle.kts b/buildSrc/src/main/kotlin/version.gradle.kts index af69c2aa..43a0f30a 100644 --- a/buildSrc/src/main/kotlin/version.gradle.kts +++ b/buildSrc/src/main/kotlin/version.gradle.kts @@ -10,6 +10,8 @@ tasks.register("increaseMajorVersion") { group = "version" doLast { properties.major += 1 + properties.minor = 0 + properties.patch = 0 properties.store() } } @@ -18,6 +20,7 @@ tasks.register("increaseMinorVersion") { group = "version" doLast { properties.minor += 1 + properties.patch += 0 properties.store() } } From 2a5d82596b957d61241a0db43b69ef6eb2ad165f Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Mon, 9 Oct 2023 07:25:14 +0200 Subject: [PATCH 4/4] fix: Patch not Reset correctly --- buildSrc/src/main/kotlin/version.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/version.gradle.kts b/buildSrc/src/main/kotlin/version.gradle.kts index 43a0f30a..a11fad2c 100644 --- a/buildSrc/src/main/kotlin/version.gradle.kts +++ b/buildSrc/src/main/kotlin/version.gradle.kts @@ -20,7 +20,7 @@ tasks.register("increaseMinorVersion") { group = "version" doLast { properties.minor += 1 - properties.patch += 0 + properties.patch = 0 properties.store() } }