From 60c7102e05f6d7bd7d60efdaf77ab2ce2dcc7ea3 Mon Sep 17 00:00:00 2001 From: gabfssilva Date: Tue, 23 Jan 2024 13:26:07 -0300 Subject: [PATCH] add os detector plugin --- build.gradle.kts | 115 +++++++++++++++++++++++++++------------------ libs.versions.toml | 3 ++ 2 files changed, 71 insertions(+), 47 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 44e6166e..38b05b90 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,12 +6,13 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import com.android.build.gradle.LibraryExtension as AndroidExtension plugins { + alias(libs.plugins.setup.android.sdk) alias(libs.plugins.android) apply false alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.kotest.multiplatform) alias(libs.plugins.dokka) alias(libs.plugins.nexus.publish) apply false - alias(libs.plugins.setup.android.sdk) + alias(libs.plugins.os.detector) `maven-publish` signing @@ -46,6 +47,7 @@ subprojects { apply(plugin = "maven-publish") apply(plugin = "org.jetbrains.dokka") apply(plugin = "signing") + apply(plugin = "com.google.osdetector") version = "1.0.0-alpha13" group = "com.river-kt" @@ -92,12 +94,10 @@ subprojects { } } - afterEvaluate { - if (androidEnabled()) { - val androidUnitTest by getting { - dependencies { - implementation(rootProject.libs.kotest.junit5) - } + onAndroidEnabled { + val androidUnitTest by getting { + dependencies { + implementation(rootProject.libs.kotest.junit5) } } } @@ -161,10 +161,6 @@ subprojects { return@forEach } - publication.artifact(tasks["sourcesJar"]) { - classifier = "sources" - } - publication.artifact(tasks["javadocJar"]) { classifier = "javadoc" } @@ -244,48 +240,54 @@ subprojects { dependsOn(tasks.withType()) } - val publishWindowsArtifacts by tasks.registering { - dependsOn( - tasks - .withType() - .filter { it.name.contains("mingw", ignoreCase = true) } - ) + onWindows { + val publishWindowsArtifacts by tasks.registering { + dependsOn( + tasks + .withType() + .filter { it.name.contains("mingw", ignoreCase = true) } + ) + } } - val publishOSXArtifacts by tasks.registering { - val appleOs = listOf("ios", "macos", "watchos", "tvos") + onMacOS { + val publishOSXArtifacts by tasks.registering { + val appleOs = listOf("ios", "macos", "watchos", "tvos") - dependsOn( - tasks - .withType() - .filter { p -> - appleOs.any { p.name.contains(it, ignoreCase = true) } - } - ) + dependsOn( + tasks + .withType() + .filter { p -> + appleOs.any { p.name.contains(it, ignoreCase = true) } + } + ) + } } - val publishJvmArtifacts by tasks.registering { - dependsOn( - tasks - .withType() - .filter { it.name.contains("jvm", ignoreCase = true) } - ) - } + onLinux { + val publishJvmArtifacts by tasks.registering { + dependsOn( + tasks + .withType() + .filter { it.name.contains("jvm", ignoreCase = true) } + ) + } - val publishLinuxArtifacts by tasks.registering { - dependsOn( - tasks - .withType() - .filter { it.name.contains("linux", ignoreCase = true) } - ) - } + val publishLinuxArtifacts by tasks.registering { + dependsOn( + tasks + .withType() + .filter { it.name.contains("linux", ignoreCase = true) } + ) + } - val publishJsArtifacts by tasks.registering { - dependsOn( - tasks - .withType() - .filter { it.name.contains("js", ignoreCase = true) } - ) + val publishJsArtifacts by tasks.registering { + dependsOn( + tasks + .withType() + .filter { it.name.contains("js", ignoreCase = true) } + ) + } } signing { @@ -321,4 +323,23 @@ fun Task.skipExamples() { onlyIf { !project.path.contains("examples") } } -fun Project.androidEnabled() = pluginManager.hasPlugin("com.android.library") +fun Project.onAndroidEnabled(block: () -> Unit) { + afterEvaluate { + if (pluginManager.hasPlugin("com.android.library")) block() + } +} + +fun Project.onWindows(block: () -> Unit) { + if (os == "windows") block() +} + +fun Project.onLinux(block: () -> Unit) { + if (os == "linux") block() +} + +fun Project.onMacOS(block: () -> Unit) { + if (os == "osx") block() +} + +val Project.os: String + get() = osdetector.os diff --git a/libs.versions.toml b/libs.versions.toml index 4892b05e..e620f97c 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -32,6 +32,7 @@ turbine = "1.0.0" kotlinx-datetime = "0.5.0" android = "8.1.4" setup-android-sdk = "3.1.0" +os-detector = "1.7.3" [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } @@ -47,6 +48,8 @@ setup-android-sdk = { id = "com.quittle.setup-android-sdk", version.ref = "setup dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version = "1.3.0" } +os-detector = { id = "com.google.osdetector", version.ref = "os-detector" } + [libraries] # kotlin coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }