diff --git a/build.gradle.kts b/build.gradle.kts index 662dce2..a0330e3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,6 @@ +import java.text.SimpleDateFormat +import java.util.* + @Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { alias(libs.plugins.android.library) apply false @@ -18,12 +21,42 @@ buildscript { } allprojects { - group = "uninit.common" - version = "0.1.0" -} + group = "uninit" + extra["root-maven-url"] = "https://repo.uninit.dev/" + val ci = System.getenv("CI") != null + val isRelease = System.getenv("GITHUB_EVENT_NAME") == "release" + + version = "0.0.1" + if (ci && !isRelease) { + version = "${version.toString()}-${SimpleDateFormat("YYYYMMdd").format(Date(System.currentTimeMillis()))}-${System.getenv("GITHUB_SHA").slice(0..6)}" // todo: add date + } + if (!ci) { + version = "${version.toString()}-LOCAL#${System.currentTimeMillis()}" + } + + /* + * If SNAPSHOT: + * version = "VERSION-YYYYMMdd-HASH" + * If not CI: + * version = "VERSION-LOCAL#TIMESTAMP" + * If RELEASE: + * version = "VERSION" + */ + + val mavenRepo: PublishingExtension.() -> Unit = { + repositories { + maven { + name = "uninit" + url = uri("${extra["root-maven-url"]}${if (ci) "snapshots" else "releases"}") + credentials { + username = "admin" + password = System.getenv("REPOSILITE_PASSWORD") + } + } + } + } -subprojects { - buildDir = file(rootProject.buildDir.absolutePath + "/" + project.name) + extra["maven-repository"] = mavenRepo } true // Needed to make the Suppress annotation work for the plugins block \ No newline at end of file diff --git a/common-compose/build.gradle.kts b/common-compose/build.gradle.kts index 504b27a..73a87f7 100644 --- a/common-compose/build.gradle.kts +++ b/common-compose/build.gradle.kts @@ -32,6 +32,7 @@ kotlin { compileOnly(libs.koin.compose) implementation(project(":common")) + } resources.srcDirs("resources") } @@ -64,33 +65,16 @@ android { jvmToolchain(17) } } - publishing { - var versionStr = project.version.toString() - val ci = System.getenv("CI") != null && System.getenv("GITHUB_EVENT_NAME") != "release" - var repo = "releases" - if (ci) { - val commitHash = System.getenv("GITHUB_SHA").slice(0..6) - versionStr += "-#$commitHash" - repo = "snapshots" - } - repositories { - maven { - name = "uninit" - url = uri("https://repo.uninit.dev/$repo") - credentials { - username = "admin" - password = System.getenv("REPOSILITE_PASSWORD") - } - } + @Suppress("UNCHECKED_CAST") + (extra["maven-repository"] as (PublishingExtension.() -> Unit)?)?.invoke(this) - } publications { - create("uninit.common-compose") { + create("uninit.common.compose") { groupId = "uninit" artifactId = "common-compose" - version = versionStr + version = project.version.toString() + from(components["kotlin"]) } } - -} \ No newline at end of file +} diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 4568995..0e42e78 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -59,33 +59,18 @@ android { } publishing { - var versionStr = project.version.toString() - val ci = System.getenv("CI") != null && System.getenv("GITHUB_EVENT_NAME") != "release" - var repo = "releases" - if (ci) { - val commitHash = System.getenv("GITHUB_SHA").slice(0..6) - versionStr += "-#$commitHash" - repo = "snapshots" - } - repositories { - maven { - name = "uninit" - url = uri("https://repo.uninit.dev/$repo") - credentials { - username = "admin" - password = System.getenv("REPOSILITE_PASSWORD") - } - } - - } + @Suppress("UNCHECKED_CAST") + (extra["maven-repository"] as (PublishingExtension.() -> Unit)?)?.invoke(this) + publications { create("uninit.common") { groupId = "uninit" artifactId = "common" - version = versionStr + version = project.version.toString() + from(components["kotlin"]) } } - } + true \ No newline at end of file