2rabs/nito-app

View on GitHub
build-logic/src/main/kotlin/club/nito/primitive/KmpComposePlugin.kt

Summary

Maintainability
B
4 hrs
Test Coverage
package club.nito.primitive

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension

@Suppress("unused")
class KmpComposePlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply("org.jetbrains.compose")
                apply("org.jetbrains.kotlin.plugin.compose")
            }
            composeCompiler {
                // Enable 'strong skipping'
                // https://medium.com/androiddevelopers/jetpack-compose-strong-skipping-mode-explained-cbdb2aa4b900
                enableStrongSkippingMode.set(true)
            }
            val compose = (extensions["compose"] as org.jetbrains.compose.ComposeExtension)
            kotlin {
                with(sourceSets) {
                    getByName("commonMain").apply {
                        dependencies {
                            implementation(compose.dependencies.runtime)
                            implementation(compose.dependencies.foundation)
                            implementation(compose.dependencies.material3)
                            @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
                            implementation(compose.dependencies.components.resources)

                            implementation(libs.library("precompose"))
                        }
                    }
                    findByName("androidMain")?.apply {
                        dependencies {
                            implementation(libs.library("androidxActivityActivityCompose"))
                        }
                    }
                }
            }
        }
    }
}

private fun Project.composeCompiler(block: ComposeCompilerGradlePluginExtension.() -> Unit) {
    extensions.configure<ComposeCompilerGradlePluginExtension>(block)
}