Skip to content

Commit

Permalink
Update KMP project configurations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Nov 7, 2023
1 parent d8ef783 commit c1cf993
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 73 deletions.
3 changes: 2 additions & 1 deletion android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.android.build.api.variant.HasUnitTestBuilder
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
import com.google.firebase.perf.plugin.FirebasePerfExtension
import io.github.reactivecircus.kstreamlined.buildlogic.FlavorDimensions
Expand Down Expand Up @@ -169,7 +170,7 @@ androidComponents {
it.enable = it.flavorName == ProductFlavors.PROD && it.buildType == "release"
|| it.flavorName != ProductFlavors.PROD && it.buildType == "debug"
|| it.flavorName == ProductFlavors.DEV && it.buildType == "benchmark"
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
it.enableAndroidTest = false
}

Expand Down
4 changes: 3 additions & 1 deletion android/ui/ui-common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.android.build.api.variant.HasUnitTestBuilder

plugins {
id("kstreamlined.android.library")
id("kstreamlined.android.library.compose")
Expand All @@ -12,7 +14,7 @@ android {

androidComponents {
beforeVariants {
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
it.enableAndroidTest = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kotlin {
}
}
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(20))
languageVersion.set(JavaLanguageVersion.of(21))
vendor.set(JvmVendorSpec.AZUL)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
@file:Suppress("UNUSED_VARIABLE")

package io.github.reactivecircus.kstreamlined.buildlogic

import org.gradle.api.Project
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
Expand All @@ -28,23 +23,7 @@ internal fun KotlinMultiplatformExtension.configureKMMCommon(
iosX64()
}

with(sourceSets) {
val commonMain by getting
val iosArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosArm64Main.dependsOn(this)
if (project.isAppleSilicon) {
val iosSimulatorArm64Main by getting
iosSimulatorArm64Main.dependsOn(this)
} else {
val iosX64Main by getting
iosX64Main.dependsOn(this)
}
}
}

sourceSets.all {
sourceSets.configureEach {
languageSettings {
applyLanguageSettings()
}
Expand All @@ -54,38 +33,18 @@ internal fun KotlinMultiplatformExtension.configureKMMCommon(
/**
* Apply test configs to KMM project.
*/
internal fun KotlinMultiplatformExtension.configureKMMTest(
project: Project,
enableJvmTest: Boolean = true,
enableIosTest: Boolean = true,
) {
internal fun KotlinMultiplatformExtension.configureKMMTest() {
with(sourceSets) {
val commonTest by getting {
commonTest {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
if (enableJvmTest) {
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
}
}
}
if (enableIosTest) {
val iosArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosArm64Test.dependsOn(this)
if (project.isAppleSilicon) {
val iosSimulatorArm64Test by getting
iosSimulatorArm64Test.dependsOn(this)
} else {
val iosX64Test by getting
iosX64Test.dependsOn(this)
}
jvmTest {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
@Suppress("MagicNumber")
internal fun KotlinProjectExtension.configureKotlinJvm(target: Project) {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(20))
languageVersion.set(JavaLanguageVersion.of(21))
vendor.set(JvmVendorSpec.AZUL)
}
target.tasks.withType<KotlinJvmCompile>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package io.github.reactivecircus.kstreamlined.buildlogic

import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.HasUnitTestBuilder
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.findByType
Expand All @@ -21,29 +22,29 @@ internal fun Project.configureSlimTests() {
// disable unit test tasks on the release, benchmark build types for Android Library projects
extensions.findByType<LibraryAndroidComponentsExtension>()?.run {
beforeVariants(selector().withBuildType("release")) {
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
}
beforeVariants(selector().withBuildType("benchmark")) {
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
}
}

// disable unit test tasks on the release, benchmark build types and all non-dev flavors for Android Application projects.
extensions.findByType<ApplicationAndroidComponentsExtension>()?.run {
beforeVariants(selector().withBuildType("release")) {
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
}
beforeVariants(selector().withBuildType("benchmark")) {
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
}
beforeVariants(selector().withFlavor(FlavorDimensions.ENVIRONMENT to ProductFlavors.DEMO)) {
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
}
beforeVariants(selector().withFlavor(FlavorDimensions.ENVIRONMENT to ProductFlavors.MOCK)) {
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
}
beforeVariants(selector().withFlavor(FlavorDimensions.ENVIRONMENT to ProductFlavors.PROD)) {
it.enableUnitTest = false
(it as HasUnitTestBuilder).enableUnitTest = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class AndroidApplicationConventionPlugin : Plugin<Project> {

extensions.configure<KotlinAndroidProjectExtension> {
configureKotlinJvm(target)
sourceSets.all {
sourceSets.configureEach {
languageSettings {
applyLanguageSettings()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class AndroidLibraryConventionPlugin : Plugin<Project> {

extensions.configure<KotlinAndroidProjectExtension> {
configureKotlinJvm(target)
sourceSets.all {
sourceSets.configureEach {
languageSettings {
applyLanguageSettings()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class AndroidTestConventionPlugin : Plugin<Project> {

extensions.configure<KotlinAndroidProjectExtension> {
configureKotlinJvm(target)
sourceSets.all {
sourceSets.configureEach {
languageSettings {
applyLanguageSettings()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class KMMTestConventionPlugin : Plugin<Project> {
pluginManager.apply("org.jetbrains.kotlin.multiplatform")

extensions.configure<KotlinMultiplatformExtension> {
configureKMMTest(target)
configureKMMTest()
}
}
}
2 changes: 1 addition & 1 deletion kmm/apollo-models/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apollo {

kotlin {
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
api(libs.apollo.api)
}
Expand Down
2 changes: 1 addition & 1 deletion kmm/core-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

kotlin {
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
implementation(libs.kotlinx.coroutines.core)
}
Expand Down
2 changes: 1 addition & 1 deletion kmm/data-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

kotlin {
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
api(project(":kmm:apollo-models"))
implementation(libs.kotlinx.coroutines.core)
Expand Down
4 changes: 2 additions & 2 deletions kmm/data-runtime-cloud/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

kotlin {
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
api(project(":kmm:data-common"))
api(libs.apollo.runtime)
Expand All @@ -14,7 +14,7 @@ kotlin {
implementation(libs.kermit)
}
}
val commonTest by getting {
commonTest {
dependencies {
implementation(project(":kmm:test-utils"))
implementation(libs.apollo.testingSupport)
Expand Down
4 changes: 2 additions & 2 deletions kmm/data-runtime-edge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ plugins {

kotlin {
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
api(project(":kmm:data-common"))
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kermit)
}
}
val commonTest by getting {
commonTest {
dependencies {
implementation(libs.kotlinx.coroutines.test)
}
Expand Down
4 changes: 2 additions & 2 deletions kmm/data-testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ plugins {

kotlin {
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
api(project(":kmm:data-common"))
implementation(libs.kotlinx.coroutines.core)
}
}
val commonTest by getting {
commonTest {
dependencies {
implementation(libs.kotlinx.coroutines.test)
}
Expand Down
2 changes: 1 addition & 1 deletion kmm/test-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

kotlin {
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
api(libs.kotlinx.coroutines.test)
}
Expand Down

0 comments on commit c1cf993

Please sign in to comment.