Skip to content

Commit

Permalink
Migrate build script to use Hierarchy Template (#379)
Browse files Browse the repository at this point in the history
* Migrate build script to use Hierarchy Template

* update multiplatform sample

* fix lint

* publishing only one Android variant
  • Loading branch information
DevSrSouza authored Apr 7, 2024
1 parent 02b0877 commit b7741b8
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 203 deletions.
92 changes: 26 additions & 66 deletions buildSrc/src/main/kotlin/Setup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import org.gradle.kotlin.dsl.getting
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.withType
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.hasPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand Down Expand Up @@ -71,7 +73,6 @@ fun Project.setupModuleForComposeMultiplatform(
withKotlinExplicitMode: Boolean = true,
fullyMultiplatform: Boolean = false,
enableWasm: Boolean = true,
iosPrefixName: String = "ios" // only used in ios sample
) {
plugins.withType<org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper> {
extensions.configure<KotlinMultiplatformExtension> {
Expand All @@ -85,8 +86,28 @@ fun Project.setupModuleForComposeMultiplatform(
}
}

applyDefaultHierarchyTemplate {
common {
if(fullyMultiplatform) {
group("commonWeb") {
withJs()
if(enableWasm) {
withWasm()
}
}
}
group("jvm") {
withCompilations {
it.target.targetName == "desktop" || it.target is KotlinAndroidTarget
}
}
}
}

androidTarget {
publishAllLibraryVariants()
if (plugins.hasPlugin("com.vanniktech.maven.publish")) {
publishLibraryVariants("release")
}
}
jvm("desktop")

Expand All @@ -100,70 +121,9 @@ fun Project.setupModuleForComposeMultiplatform(
}
macosX64()
macosArm64()
ios(iosPrefixName)
iosSimulatorArm64("${iosPrefixName}SimulatorArm64")
}

sourceSets {
/* Source sets structure
common
├─ jvm
├─ android
├─ desktop
*/
val commonMain by getting
val commonTest by getting
val jvmMain by creating {
dependsOn(commonMain)
}
val jvmTest by creating {
dependsOn(commonTest)
}


val desktopMain by getting {
dependsOn(jvmMain)
}
val androidMain by getting {
dependsOn(jvmMain)
}
val desktopTest by getting {
dependsOn(jvmTest)
}

if (fullyMultiplatform) {
val commonWebMain by creating {
dependsOn(commonMain)
}

val jsMain by getting
jsMain.dependsOn(commonWebMain)

val nativeMain by creating {
dependsOn(commonMain)
}

val macosMain by creating {
dependsOn(nativeMain)
}
val macosX64Main by getting {
dependsOn(macosMain)
}
val macosArm64Main by getting {
dependsOn(macosMain)
}
val iosMain = getByName(iosPrefixName + "Main").apply {
dependsOn(nativeMain)
}
val iosSimulatorArm64Main = getByName(iosPrefixName + "SimulatorArm64Main").apply {
dependsOn(iosMain)
}

if (enableWasm) {
val wasmJsMain by getting
wasmJsMain.dependsOn(commonWebMain)
}
}
iosArm64()
iosX64()
iosSimulatorArm64()
}
}

Expand Down
22 changes: 9 additions & 13 deletions samples/multiplatform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,18 @@ kotlin {
}

sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.material)
implementation(compose.runtime)
commonMain.dependencies {
implementation(compose.material)
implementation(compose.runtime)

implementation(projects.voyagerCore)
implementation(projects.voyagerNavigator)
implementation(libs.coroutines.core)
}
implementation(projects.voyagerCore)
implementation(projects.voyagerNavigator)
implementation(libs.coroutines.core)
}

val androidMain by getting {
dependencies {
implementation(libs.appCompat)
implementation(libs.compose.activity)
}
androidMain.dependencies {
implementation(libs.appCompat)
implementation(libs.compose.activity)
}

val desktopMain by getting {
Expand Down
26 changes: 10 additions & 16 deletions voyager-bottom-sheet-navigator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,20 @@ android {

kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(projects.voyagerCore)
api(projects.voyagerNavigator)
compileOnly(compose.runtime)
compileOnly(compose.material)
}
commonMain.dependencies {
api(projects.voyagerCore)
api(projects.voyagerNavigator)
compileOnly(compose.runtime)
compileOnly(compose.material)
}

val jvmTest by getting {
dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
jvmTest.dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}

val androidMain by getting {
dependencies {
implementation(libs.compose.activity)
}
androidMain.dependencies {
implementation(libs.compose.activity)
}
}
}
32 changes: 13 additions & 19 deletions voyager-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,22 @@ android {

kotlin {
sourceSets {
val commonMain by getting {
dependencies {
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
implementation(libs.coroutines.core)
}
commonMain.dependencies {
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
implementation(libs.coroutines.core)
}
val jvmTest by getting {
dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
jvmTest.dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
val androidMain by getting {
dependencies {
implementation(libs.compose.activity)
androidMain.dependencies {
implementation(libs.compose.activity)

implementation(libs.lifecycle.runtime)
implementation(libs.lifecycle.savedState)
implementation(libs.lifecycle.viewModelKtx)
implementation(libs.lifecycle.viewModelCompose)
}
implementation(libs.lifecycle.runtime)
implementation(libs.lifecycle.savedState)
implementation(libs.lifecycle.viewModelKtx)
implementation(libs.lifecycle.viewModelCompose)
}
val commonWebMain by getting {
dependencies {
Expand Down
24 changes: 10 additions & 14 deletions voyager-kodein/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ android {

kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(projects.voyagerCore)
api(projects.voyagerScreenmodel)
api(projects.voyagerNavigator)
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
compileOnly(libs.kodein)
}
commonMain.dependencies {
api(projects.voyagerCore)
api(projects.voyagerScreenmodel)
api(projects.voyagerNavigator)
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
compileOnly(libs.kodein)
}

val jvmTest by getting {
dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
jvmTest.dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
}
}
16 changes: 7 additions & 9 deletions voyager-koin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ android {

kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(projects.voyagerCore)
api(projects.voyagerScreenmodel)
api(projects.voyagerNavigator)
commonMain.dependencies {
api(projects.voyagerCore)
api(projects.voyagerScreenmodel)
api(projects.voyagerNavigator)

compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)

implementation(libs.coroutines.core)
}
implementation(libs.coroutines.core)
}
}
}
Expand Down
24 changes: 9 additions & 15 deletions voyager-navigator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,19 @@ android {

kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(projects.voyagerCore)
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
}
commonMain.dependencies {
api(projects.voyagerCore)
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
}

val jvmTest by getting {
dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
jvmTest.dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}

val androidMain by getting {
dependencies {
implementation(libs.compose.activity)
}
androidMain.dependencies {
implementation(libs.compose.activity)
}
}
}
18 changes: 7 additions & 11 deletions voyager-rxjava/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ android {

kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
api(projects.voyagerCore)
api(projects.voyagerScreenmodel)
compileOnly(libs.rxjava)
}
jvmMain.dependencies {
api(projects.voyagerCore)
api(projects.voyagerScreenmodel)
compileOnly(libs.rxjava)
}
val jvmTest by getting {
dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
jvmTest.dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
}
}
22 changes: 9 additions & 13 deletions voyager-screenmodel/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ android {

kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(projects.voyagerCore)
api(projects.voyagerNavigator)
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
implementation(libs.coroutines.core)
}
commonMain.dependencies {
api(projects.voyagerCore)
api(projects.voyagerNavigator)
compileOnly(compose.runtime)
compileOnly(compose.runtimeSaveable)
implementation(libs.coroutines.core)
}

val jvmTest by getting {
dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
jvmTest.dependencies {
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
}
}
Loading

0 comments on commit b7741b8

Please sign in to comment.