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/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/buildSrc/src/main/kotlin/version.gradle.kts b/buildSrc/src/main/kotlin/version.gradle.kts new file mode 100644 index 00000000..a11fad2c --- /dev/null +++ b/buildSrc/src/main/kotlin/version.gradle.kts @@ -0,0 +1,68 @@ +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.minor = 0 + properties.patch = 0 + properties.store() + } +} + +tasks.register("increaseMinorVersion") { + group = "version" + doLast { + properties.minor += 1 + properties.patch = 0 + 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 2b5d0b87..8579b27f 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 = rootProject.extra["projectVersion"].toString() + 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() } 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