From 807e6798b07de06f29128920cb19c3b3c6ffad13 Mon Sep 17 00:00:00 2001 From: Christian De Angelis Date: Sat, 2 Dec 2023 19:05:28 -0500 Subject: [PATCH] Refactor internal project plugins. Now the `ozone-multiplatform` convention plugin is typically the main entrypoint for configuring which targets are available for a module. --- api-gen-runtime-internal/build.gradle.kts | 19 ++---- api-gen-runtime/build.gradle.kts | 19 ++---- app/android/build.gradle.kts | 38 ++++++----- .../{main => androidMain}/AndroidManifest.xml | 0 .../ic_launcher-playstore.png | Bin .../java/sh/christian/ozone/MainActivity.kt | 0 .../java/sh/christian/ozone/StatusBarTheme.kt | 0 .../res/mipmap-anydpi-v26/ic_launcher.xml | 0 .../mipmap-anydpi-v26/ic_launcher_round.xml | 0 .../res/mipmap-hdpi/ic_launcher.png | Bin .../mipmap-hdpi/ic_launcher_foreground.png | Bin .../res/mipmap-hdpi/ic_launcher_round.png | Bin .../res/mipmap-mdpi/ic_launcher.png | Bin .../mipmap-mdpi/ic_launcher_foreground.png | Bin .../res/mipmap-mdpi/ic_launcher_round.png | Bin .../res/mipmap-xhdpi/ic_launcher.png | Bin .../mipmap-xhdpi/ic_launcher_foreground.png | Bin .../res/mipmap-xhdpi/ic_launcher_round.png | Bin .../res/mipmap-xxhdpi/ic_launcher.png | Bin .../mipmap-xxhdpi/ic_launcher_foreground.png | Bin .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin .../res/mipmap-xxxhdpi/ic_launcher.png | Bin .../mipmap-xxxhdpi/ic_launcher_foreground.png | Bin .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin .../res/values/ic_launcher_background.xml | 0 .../res/values/strings.xml | 0 app/common/build.gradle.kts | 14 +++-- .../sh/christian/ozone/api/dispatching.jvm.kt | 0 .../christian/ozone/ui/DynamicDarkMode.jvm.kt | 0 .../ui/compose/OnBackPressedModifier.jvm.kt | 0 .../ozone/ui/compose/SystemInsets.jvm.kt | 0 .../ozone/ui/compose/ZoomableImage.jvm.kt | 0 .../sh/christian/ozone/ui/compose/type.jvm.kt | 0 .../sh/christian/ozone/util/time.jvm.kt | 0 app/desktop/build.gradle.kts | 11 ++-- app/store/build.gradle.kts | 8 ++- .../sh/christian/ozone/store/Storage.jvm.kt | 0 app/web/build.gradle.kts | 11 ++-- bluesky/build.gradle.kts | 17 ++--- .../christian/plugin/MultiplatformPlugin.kt | 24 +------ .../sh/christian/plugin/OzoneExtension.kt | 59 ++++++++++++++++++ 41 files changed, 124 insertions(+), 96 deletions(-) rename app/android/src/{main => androidMain}/AndroidManifest.xml (100%) rename app/android/src/{main => androidMain}/ic_launcher-playstore.png (100%) rename app/android/src/{main => androidMain}/java/sh/christian/ozone/MainActivity.kt (100%) rename app/android/src/{main => androidMain}/java/sh/christian/ozone/StatusBarTheme.kt (100%) rename app/android/src/{main => androidMain}/res/mipmap-anydpi-v26/ic_launcher.xml (100%) rename app/android/src/{main => androidMain}/res/mipmap-anydpi-v26/ic_launcher_round.xml (100%) rename app/android/src/{main => androidMain}/res/mipmap-hdpi/ic_launcher.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-hdpi/ic_launcher_foreground.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-hdpi/ic_launcher_round.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-mdpi/ic_launcher.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-mdpi/ic_launcher_foreground.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-mdpi/ic_launcher_round.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xhdpi/ic_launcher.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xhdpi/ic_launcher_foreground.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xhdpi/ic_launcher_round.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xxhdpi/ic_launcher.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xxhdpi/ic_launcher_foreground.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xxhdpi/ic_launcher_round.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xxxhdpi/ic_launcher.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xxxhdpi/ic_launcher_foreground.png (100%) rename app/android/src/{main => androidMain}/res/mipmap-xxxhdpi/ic_launcher_round.png (100%) rename app/android/src/{main => androidMain}/res/values/ic_launcher_background.xml (100%) rename app/android/src/{main => androidMain}/res/values/strings.xml (100%) rename app/common/src/{desktopMain => jvmMain}/kotlin/sh/christian/ozone/api/dispatching.jvm.kt (100%) rename app/common/src/{desktopMain => jvmMain}/kotlin/sh/christian/ozone/ui/DynamicDarkMode.jvm.kt (100%) rename app/common/src/{desktopMain => jvmMain}/kotlin/sh/christian/ozone/ui/compose/OnBackPressedModifier.jvm.kt (100%) rename app/common/src/{desktopMain => jvmMain}/kotlin/sh/christian/ozone/ui/compose/SystemInsets.jvm.kt (100%) rename app/common/src/{desktopMain => jvmMain}/kotlin/sh/christian/ozone/ui/compose/ZoomableImage.jvm.kt (100%) rename app/common/src/{desktopMain => jvmMain}/kotlin/sh/christian/ozone/ui/compose/type.jvm.kt (100%) rename app/common/src/{desktopMain => jvmMain}/kotlin/sh/christian/ozone/util/time.jvm.kt (100%) rename app/store/src/{desktopMain => jvmMain}/kotlin/sh/christian/ozone/store/Storage.jvm.kt (100%) create mode 100644 build-logic/src/main/kotlin/sh/christian/plugin/OzoneExtension.kt diff --git a/api-gen-runtime-internal/build.gradle.kts b/api-gen-runtime-internal/build.gradle.kts index a8b7eb98..36f0d0d8 100644 --- a/api-gen-runtime-internal/build.gradle.kts +++ b/api-gen-runtime-internal/build.gradle.kts @@ -1,22 +1,15 @@ plugins { - kotlin("multiplatform") - id("ozone-base") + id("ozone-multiplatform") id("ozone-publish") kotlin("plugin.serialization") } -kotlin { - jvm { - compilations.all { - kotlinOptions.jvmTarget = "11" - } - } - js(IR) { - browser() - nodejs() - binaries.executable() - } +ozone { + js() + jvm() +} +kotlin { sourceSets { val commonMain by getting { dependencies { diff --git a/api-gen-runtime/build.gradle.kts b/api-gen-runtime/build.gradle.kts index 82e3f2e3..af47abbf 100644 --- a/api-gen-runtime/build.gradle.kts +++ b/api-gen-runtime/build.gradle.kts @@ -1,22 +1,15 @@ plugins { - kotlin("multiplatform") - id("ozone-base") + id("ozone-multiplatform") id("ozone-publish") kotlin("plugin.serialization") } -kotlin { - jvm { - compilations.all { - kotlinOptions.jvmTarget = "11" - } - } - js(IR) { - browser() - nodejs() - binaries.executable() - } +ozone { + js() + jvm() +} +kotlin { sourceSets { val commonMain by getting { dependencies { diff --git a/app/android/build.gradle.kts b/app/android/build.gradle.kts index 59f0d4dc..3fd24861 100644 --- a/app/android/build.gradle.kts +++ b/app/android/build.gradle.kts @@ -1,24 +1,30 @@ plugins { - id("com.android.application") - kotlin("android") - id("ozone-android") + id("ozone-multiplatform") id("ozone-compose") } -dependencies { - implementation(project(":app:common")) - implementation(libs.androidx.activity.compose) - implementation(libs.androidx.appcompat) - implementation(libs.androidx.core) - implementation(libs.retainedactivity) -} +ozone { + androidApp { + namespace = "sh.christian.ozone" -android { - namespace = "sh.christian.ozone" + defaultConfig { + applicationId = "sh.christian.ozone" + versionCode = 100 + versionName = version.toString() + } + } +} - defaultConfig { - applicationId = "sh.christian.ozone" - versionCode = 100 - versionName = version.toString() +kotlin { + sourceSets { + val androidMain by getting { + dependencies { + implementation(project(":app:common")) + implementation(libs.androidx.activity.compose) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.core) + implementation(libs.retainedactivity) + } + } } } diff --git a/app/android/src/main/AndroidManifest.xml b/app/android/src/androidMain/AndroidManifest.xml similarity index 100% rename from app/android/src/main/AndroidManifest.xml rename to app/android/src/androidMain/AndroidManifest.xml diff --git a/app/android/src/main/ic_launcher-playstore.png b/app/android/src/androidMain/ic_launcher-playstore.png similarity index 100% rename from app/android/src/main/ic_launcher-playstore.png rename to app/android/src/androidMain/ic_launcher-playstore.png diff --git a/app/android/src/main/java/sh/christian/ozone/MainActivity.kt b/app/android/src/androidMain/java/sh/christian/ozone/MainActivity.kt similarity index 100% rename from app/android/src/main/java/sh/christian/ozone/MainActivity.kt rename to app/android/src/androidMain/java/sh/christian/ozone/MainActivity.kt diff --git a/app/android/src/main/java/sh/christian/ozone/StatusBarTheme.kt b/app/android/src/androidMain/java/sh/christian/ozone/StatusBarTheme.kt similarity index 100% rename from app/android/src/main/java/sh/christian/ozone/StatusBarTheme.kt rename to app/android/src/androidMain/java/sh/christian/ozone/StatusBarTheme.kt diff --git a/app/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/android/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from app/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml rename to app/android/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/app/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/android/src/androidMain/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from app/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml rename to app/android/src/androidMain/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/app/android/src/main/res/mipmap-hdpi/ic_launcher.png b/app/android/src/androidMain/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from app/android/src/main/res/mipmap-hdpi/ic_launcher.png rename to app/android/src/androidMain/res/mipmap-hdpi/ic_launcher.png diff --git a/app/android/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/app/android/src/androidMain/res/mipmap-hdpi/ic_launcher_foreground.png similarity index 100% rename from app/android/src/main/res/mipmap-hdpi/ic_launcher_foreground.png rename to app/android/src/androidMain/res/mipmap-hdpi/ic_launcher_foreground.png diff --git a/app/android/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/android/src/androidMain/res/mipmap-hdpi/ic_launcher_round.png similarity index 100% rename from app/android/src/main/res/mipmap-hdpi/ic_launcher_round.png rename to app/android/src/androidMain/res/mipmap-hdpi/ic_launcher_round.png diff --git a/app/android/src/main/res/mipmap-mdpi/ic_launcher.png b/app/android/src/androidMain/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from app/android/src/main/res/mipmap-mdpi/ic_launcher.png rename to app/android/src/androidMain/res/mipmap-mdpi/ic_launcher.png diff --git a/app/android/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/app/android/src/androidMain/res/mipmap-mdpi/ic_launcher_foreground.png similarity index 100% rename from app/android/src/main/res/mipmap-mdpi/ic_launcher_foreground.png rename to app/android/src/androidMain/res/mipmap-mdpi/ic_launcher_foreground.png diff --git a/app/android/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/android/src/androidMain/res/mipmap-mdpi/ic_launcher_round.png similarity index 100% rename from app/android/src/main/res/mipmap-mdpi/ic_launcher_round.png rename to app/android/src/androidMain/res/mipmap-mdpi/ic_launcher_round.png diff --git a/app/android/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/android/src/androidMain/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from app/android/src/main/res/mipmap-xhdpi/ic_launcher.png rename to app/android/src/androidMain/res/mipmap-xhdpi/ic_launcher.png diff --git a/app/android/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/app/android/src/androidMain/res/mipmap-xhdpi/ic_launcher_foreground.png similarity index 100% rename from app/android/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png rename to app/android/src/androidMain/res/mipmap-xhdpi/ic_launcher_foreground.png diff --git a/app/android/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/android/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.png similarity index 100% rename from app/android/src/main/res/mipmap-xhdpi/ic_launcher_round.png rename to app/android/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/app/android/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/android/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from app/android/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to app/android/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png diff --git a/app/android/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/app/android/src/androidMain/res/mipmap-xxhdpi/ic_launcher_foreground.png similarity index 100% rename from app/android/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png rename to app/android/src/androidMain/res/mipmap-xxhdpi/ic_launcher_foreground.png diff --git a/app/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/android/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.png similarity index 100% rename from app/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.png rename to app/android/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/app/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/android/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from app/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to app/android/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/app/android/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/app/android/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_foreground.png similarity index 100% rename from app/android/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png rename to app/android/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_foreground.png diff --git a/app/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/android/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.png similarity index 100% rename from app/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png rename to app/android/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/app/android/src/main/res/values/ic_launcher_background.xml b/app/android/src/androidMain/res/values/ic_launcher_background.xml similarity index 100% rename from app/android/src/main/res/values/ic_launcher_background.xml rename to app/android/src/androidMain/res/values/ic_launcher_background.xml diff --git a/app/android/src/main/res/values/strings.xml b/app/android/src/androidMain/res/values/strings.xml similarity index 100% rename from app/android/src/main/res/values/strings.xml rename to app/android/src/androidMain/res/values/strings.xml diff --git a/app/common/build.gradle.kts b/app/common/build.gradle.kts index d1c2eb33..95afe2ae 100644 --- a/app/common/build.gradle.kts +++ b/app/common/build.gradle.kts @@ -8,8 +8,12 @@ plugins { id("com.google.devtools.ksp") } -android { - namespace = "sh.christian.ozone.common" +ozone { + androidLibrary { + namespace = "sh.christian.ozone.common" + } + js() + jvm() } kotlin { @@ -53,8 +57,8 @@ kotlin { implementation(libs.zoomable) } } - val desktopMain by getting { - kotlin.srcDir("build/generated/ksp/desktop/desktopMain/kotlin") + val jvmMain by getting { + kotlin.srcDir("build/generated/ksp/jvm/jvmMain/kotlin") resources.srcDir("fonts") dependencies { @@ -76,6 +80,6 @@ kotlin { dependencies { add("kspAndroid", libs.kotlininject.compiler) - add("kspDesktop", libs.kotlininject.compiler) add("kspJs", libs.kotlininject.compiler) + add("kspJvm", libs.kotlininject.compiler) } diff --git a/app/common/src/desktopMain/kotlin/sh/christian/ozone/api/dispatching.jvm.kt b/app/common/src/jvmMain/kotlin/sh/christian/ozone/api/dispatching.jvm.kt similarity index 100% rename from app/common/src/desktopMain/kotlin/sh/christian/ozone/api/dispatching.jvm.kt rename to app/common/src/jvmMain/kotlin/sh/christian/ozone/api/dispatching.jvm.kt diff --git a/app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/DynamicDarkMode.jvm.kt b/app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/DynamicDarkMode.jvm.kt similarity index 100% rename from app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/DynamicDarkMode.jvm.kt rename to app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/DynamicDarkMode.jvm.kt diff --git a/app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/compose/OnBackPressedModifier.jvm.kt b/app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/compose/OnBackPressedModifier.jvm.kt similarity index 100% rename from app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/compose/OnBackPressedModifier.jvm.kt rename to app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/compose/OnBackPressedModifier.jvm.kt diff --git a/app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/compose/SystemInsets.jvm.kt b/app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/compose/SystemInsets.jvm.kt similarity index 100% rename from app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/compose/SystemInsets.jvm.kt rename to app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/compose/SystemInsets.jvm.kt diff --git a/app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/compose/ZoomableImage.jvm.kt b/app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/compose/ZoomableImage.jvm.kt similarity index 100% rename from app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/compose/ZoomableImage.jvm.kt rename to app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/compose/ZoomableImage.jvm.kt diff --git a/app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/compose/type.jvm.kt b/app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/compose/type.jvm.kt similarity index 100% rename from app/common/src/desktopMain/kotlin/sh/christian/ozone/ui/compose/type.jvm.kt rename to app/common/src/jvmMain/kotlin/sh/christian/ozone/ui/compose/type.jvm.kt diff --git a/app/common/src/desktopMain/kotlin/sh/christian/ozone/util/time.jvm.kt b/app/common/src/jvmMain/kotlin/sh/christian/ozone/util/time.jvm.kt similarity index 100% rename from app/common/src/desktopMain/kotlin/sh/christian/ozone/util/time.jvm.kt rename to app/common/src/jvmMain/kotlin/sh/christian/ozone/util/time.jvm.kt diff --git a/app/desktop/build.gradle.kts b/app/desktop/build.gradle.kts index b49da1e1..25687da3 100644 --- a/app/desktop/build.gradle.kts +++ b/app/desktop/build.gradle.kts @@ -1,17 +1,16 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { - kotlin("multiplatform") kotlin("plugin.serialization") + id("ozone-multiplatform") id("ozone-compose") } +ozone { + jvm() +} + kotlin { - jvm { - compilations.all { - kotlinOptions.jvmTarget = "11" - } - } sourceSets { val jvmMain by getting { dependencies { diff --git a/app/store/build.gradle.kts b/app/store/build.gradle.kts index 03e6d9ff..08bb419e 100644 --- a/app/store/build.gradle.kts +++ b/app/store/build.gradle.kts @@ -3,8 +3,12 @@ plugins { kotlin("plugin.serialization") } -android { - namespace = "sh.christian.ozone.store" +ozone { + androidLibrary { + namespace = "sh.christian.ozone.store" + } + js() + jvm() } kotlin { diff --git a/app/store/src/desktopMain/kotlin/sh/christian/ozone/store/Storage.jvm.kt b/app/store/src/jvmMain/kotlin/sh/christian/ozone/store/Storage.jvm.kt similarity index 100% rename from app/store/src/desktopMain/kotlin/sh/christian/ozone/store/Storage.jvm.kt rename to app/store/src/jvmMain/kotlin/sh/christian/ozone/store/Storage.jvm.kt diff --git a/app/web/build.gradle.kts b/app/web/build.gradle.kts index 7e14aaad..e31d30c4 100644 --- a/app/web/build.gradle.kts +++ b/app/web/build.gradle.kts @@ -1,17 +1,16 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack plugins { - kotlin("multiplatform") kotlin("plugin.serialization") + id("ozone-multiplatform") id("ozone-compose") } +ozone { + js() +} + kotlin { - js(IR) { - browser() - nodejs() - binaries.executable() - } sourceSets { val jsMain by getting { dependencies { diff --git a/bluesky/build.gradle.kts b/bluesky/build.gradle.kts index 73bb9f0e..683977b9 100644 --- a/bluesky/build.gradle.kts +++ b/bluesky/build.gradle.kts @@ -2,24 +2,15 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn import sh.christian.ozone.api.generator.ApiReturnType plugins { - kotlin("multiplatform") - id("ozone-base") + id("ozone-multiplatform") id("ozone-publish") id("sh.christian.ozone.generator") id("org.jetbrains.kotlinx.binary-compatibility-validator") } -kotlin { - jvm { - compilations.all { - kotlinOptions.jvmTarget = "11" - } - } - js(IR) { - browser() - nodejs() - binaries.executable() - } +ozone { + js() + jvm() } dependencies { diff --git a/build-logic/src/main/kotlin/sh/christian/plugin/MultiplatformPlugin.kt b/build-logic/src/main/kotlin/sh/christian/plugin/MultiplatformPlugin.kt index 2e764e21..2bfbadef 100644 --- a/build-logic/src/main/kotlin/sh/christian/plugin/MultiplatformPlugin.kt +++ b/build-logic/src/main/kotlin/sh/christian/plugin/MultiplatformPlugin.kt @@ -2,8 +2,7 @@ package sh.christian.plugin import org.gradle.api.Plugin import org.gradle.api.Project -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.dsl.kotlinExtension +import org.gradle.kotlin.dsl.create @Suppress("unused") class MultiplatformPlugin : Plugin { @@ -11,24 +10,5 @@ class MultiplatformPlugin : Plugin { } private fun Project.applyPlugin() { - plugins.apply("com.android.library") - plugins.apply("org.jetbrains.kotlin.multiplatform") - plugins.apply("ozone-base") - plugins.apply("ozone-android") - - (project.kotlinExtension as KotlinMultiplatformExtension).apply { - androidTarget() - - jvm("desktop") { - compilations.all { - kotlinOptions.jvmTarget = "11" - } - } - - js(IR) { - browser() - nodejs() - binaries.executable() - } - } + extensions.create("ozone", this) } diff --git a/build-logic/src/main/kotlin/sh/christian/plugin/OzoneExtension.kt b/build-logic/src/main/kotlin/sh/christian/plugin/OzoneExtension.kt new file mode 100644 index 00000000..971443c7 --- /dev/null +++ b/build-logic/src/main/kotlin/sh/christian/plugin/OzoneExtension.kt @@ -0,0 +1,59 @@ +package sh.christian.plugin + +import com.android.build.gradle.AppExtension +import com.android.build.gradle.LibraryExtension +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.dsl.kotlinExtension + +abstract class OzoneExtension( + private val project: Project, +) { + init { + project.plugins.apply("org.jetbrains.kotlin.multiplatform") + project.plugins.apply("ozone-base") + } + + fun androidLibrary(configure: LibraryExtension.() -> Unit = {}) { + project.plugins.apply("com.android.library") + project.plugins.apply("ozone-android") + kotlin { + androidTarget() + } + project.extensions.configure(configure) + } + + fun androidApp(configure: AppExtension.() -> Unit = {}) { + project.plugins.apply("com.android.application") + project.plugins.apply("ozone-android") + kotlin { + androidTarget() + } + project.extensions.configure(configure) + } + + fun js() { + kotlin { + js(IR) { + browser() + nodejs() + binaries.executable() + } + } + } + + fun jvm() { + kotlin { + jvm { + compilations.all { + kotlinOptions.jvmTarget = "11" + } + } + } + } + + private fun kotlin(configure: KotlinMultiplatformExtension.() -> Unit) { + configure(project.kotlinExtension as KotlinMultiplatformExtension) + } +}