Skip to content

Commit

Permalink
add os detector plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gabfssilva committed Jan 23, 2024
1 parent 7794a16 commit 60c7102
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 47 deletions.
115 changes: 68 additions & 47 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -161,10 +161,6 @@ subprojects {
return@forEach
}

publication.artifact(tasks["sourcesJar"]) {
classifier = "sources"
}

publication.artifact(tasks["javadocJar"]) {
classifier = "javadoc"
}
Expand Down Expand Up @@ -244,48 +240,54 @@ subprojects {
dependsOn(tasks.withType<Sign>())
}

val publishWindowsArtifacts by tasks.registering {
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.filter { it.name.contains("mingw", ignoreCase = true) }
)
onWindows {
val publishWindowsArtifacts by tasks.registering {
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.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<PublishToMavenRepository>()
.filter { p ->
appleOs.any { p.name.contains(it, ignoreCase = true) }
}
)
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.filter { p ->
appleOs.any { p.name.contains(it, ignoreCase = true) }
}
)
}
}

val publishJvmArtifacts by tasks.registering {
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.filter { it.name.contains("jvm", ignoreCase = true) }
)
}
onLinux {
val publishJvmArtifacts by tasks.registering {
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.filter { it.name.contains("jvm", ignoreCase = true) }
)
}

val publishLinuxArtifacts by tasks.registering {
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.filter { it.name.contains("linux", ignoreCase = true) }
)
}
val publishLinuxArtifacts by tasks.registering {
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.filter { it.name.contains("linux", ignoreCase = true) }
)
}

val publishJsArtifacts by tasks.registering {
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.filter { it.name.contains("js", ignoreCase = true) }
)
val publishJsArtifacts by tasks.registering {
dependsOn(
tasks
.withType<PublishToMavenRepository>()
.filter { it.name.contains("js", ignoreCase = true) }
)
}
}

signing {
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Expand Down

0 comments on commit 60c7102

Please sign in to comment.