Skip to content

Commit

Permalink
Refactor internal project plugins.
Browse files Browse the repository at this point in the history
Now the `ozone-multiplatform` convention plugin is typically the main
entrypoint for configuring which targets are available for a module.
  • Loading branch information
christiandeange committed Dec 3, 2023
1 parent 64f8f2b commit 807e679
Show file tree
Hide file tree
Showing 41 changed files with 124 additions and 96 deletions.
19 changes: 6 additions & 13 deletions api-gen-runtime-internal/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
19 changes: 6 additions & 13 deletions api-gen-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
38 changes: 22 additions & 16 deletions app/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
File renamed without changes.
File renamed without changes.
14 changes: 9 additions & 5 deletions app/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
11 changes: 5 additions & 6 deletions app/desktop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions app/store/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ plugins {
kotlin("plugin.serialization")
}

android {
namespace = "sh.christian.ozone.store"
ozone {
androidLibrary {
namespace = "sh.christian.ozone.store"
}
js()
jvm()
}

kotlin {
Expand Down
11 changes: 5 additions & 6 deletions app/web/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
17 changes: 4 additions & 13 deletions bluesky/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,13 @@ 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<Project> {
override fun apply(target: Project) = target.applyPlugin()
}

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<OzoneExtension>("ozone", this)
}
59 changes: 59 additions & 0 deletions build-logic/src/main/kotlin/sh/christian/plugin/OzoneExtension.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 807e679

Please sign in to comment.