[Gradle][KT-53342] Implement MultiplatformAndroidSourceSetLayoutV2IT
This commit is contained in:
committed by
Space
parent
3b19cf5831
commit
82d92a4e82
Generated
+1
-4
@@ -8,7 +8,4 @@
|
||||
<component name="KotlinCompilerSettings">
|
||||
<option name="additionalArguments" value="-version -Xallow-kotlin-package -Xskip-metadata-version-check" />
|
||||
</component>
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.8.0-dev-1006" />
|
||||
</component>
|
||||
</project>
|
||||
</project>
|
||||
|
||||
+33
-2
@@ -8,14 +8,45 @@ package org.jetbrains.kotlin.gradle
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import kotlin.test.assertNull
|
||||
|
||||
@MppGradlePluginTests
|
||||
@DisplayName("Multiplatform Build Reproducibility")
|
||||
@DisplayName("Multiplatform Android Source Set Layout 2")
|
||||
class MultiplatformAndroidSourceSetLayoutV2IT : KGPBaseTest() {
|
||||
|
||||
@GradleAndroidTest
|
||||
@DisplayName("test Android project with flavors")
|
||||
@AndroidTestVersions(minVersion = "7.0.4")
|
||||
fun testProjectWithFlavors(gradleVersion: GradleVersion, agpVersion: String, jdkVersion: JdkVersions.ProvidedJdk) {
|
||||
val buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion)
|
||||
project(
|
||||
"multiplatformAndroidSourceSetLayout2",
|
||||
gradleVersion,
|
||||
defaultBuildOptions.copy(androidVersion = agpVersion),
|
||||
buildJdk = jdkVersion.location
|
||||
) {
|
||||
build("test") {
|
||||
assertTasksExecuted(":testUsaPaidReleaseUnitTest")
|
||||
assertTasksExecuted(":testUsaPaidDebugUnitTest")
|
||||
assertTasksExecuted(":testUsaFreeReleaseUnitTest")
|
||||
assertTasksExecuted(":testUsaFreeDebugUnitTest")
|
||||
|
||||
assertTasksExecuted(":testGermanPaidReleaseUnitTest")
|
||||
assertTasksExecuted(":testGermanPaidDebugUnitTest")
|
||||
assertTasksExecuted(":testGermanFreeReleaseUnitTest")
|
||||
assertTasksExecuted(":testGermanFreeDebugUnitTest")
|
||||
|
||||
assertNull(task(":assembleUsaPaidDebugAndroidTest"))
|
||||
assertNull(task(":assembleUsaFreeDebugAndroidTest"))
|
||||
assertNull(task(":assembleGermanPaidDebugAndroidTest"))
|
||||
assertNull(task(":assembleGermanFreeDebugAndroidTest"))
|
||||
}
|
||||
|
||||
build("assembleAndroidTest") {
|
||||
assertTasksExecuted(":assembleUsaPaidDebugAndroidTest")
|
||||
assertTasksExecuted(":assembleUsaFreeDebugAndroidTest")
|
||||
assertTasksExecuted(":assembleGermanPaidDebugAndroidTest")
|
||||
assertTasksExecuted(":assembleGermanFreeDebugAndroidTest")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.ExperimentalKotlinGradlePluginApi
|
||||
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
|
||||
android {
|
||||
compileSdk = 31
|
||||
defaultConfig {
|
||||
minSdk = 31
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
android.flavorDimensions.add("market")
|
||||
android.flavorDimensions.add("price")
|
||||
android.productFlavors.create("german").dimension = "market"
|
||||
android.productFlavors.create("usa").dimension = "market"
|
||||
android.productFlavors.create("paid").dimension = "price"
|
||||
android.productFlavors.create("free").dimension = "price"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
android()
|
||||
jvm()
|
||||
|
||||
val commonMain by sourceSets.getting
|
||||
val commonTest by sourceSets.getting
|
||||
val androidMain by sourceSets.getting
|
||||
|
||||
val androidUnitTest by sourceSets.getting
|
||||
val androidInstrumentedTest by sourceSets.getting
|
||||
|
||||
commonTest.dependencies {
|
||||
implementation(kotlin("test-junit"))
|
||||
}
|
||||
|
||||
androidUnitTest.dependencies {
|
||||
implementation("org.robolectric:robolectric:4.8")
|
||||
implementation("androidx.test:core:1.4.0")
|
||||
implementation("androidx.test:core-ktx:1.4.0")
|
||||
}
|
||||
|
||||
androidInstrumentedTest.dependencies {
|
||||
implementation("androidx.test:runner:1.4.0")
|
||||
implementation("androidx.test:rules:1.4.0")
|
||||
}
|
||||
|
||||
sourceSets.invokeWhenCreated("androidUnitTestGermanFreeDebug") {
|
||||
dependencies {
|
||||
implementation("com.squareup.okio:okio:3.2.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
kotlin.mpp.androidSourceSetLayoutVersion=2
|
||||
android.useAndroidX=true
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.junit.Test
|
||||
|
||||
class AndroidInstrumentedTest {
|
||||
|
||||
@Test
|
||||
fun someTest() {
|
||||
commonMainExpect()
|
||||
CommonMain.invoke()
|
||||
AndroidMain.invoke()
|
||||
AndroidMain.invoke(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext)
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<manifest package="org.jetbrains.kotlin.sample"/>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
|
||||
object AndroidMain {
|
||||
operator fun invoke(context: Context): AndroidMain {
|
||||
context.applicationContext
|
||||
return this
|
||||
}
|
||||
|
||||
operator fun invoke(): AndroidMain {
|
||||
CommonMain.invoke()
|
||||
return AndroidMain
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
actual fun commonMainExpect(): CommonMain {
|
||||
return CommonMain.invoke()
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class AndroidUnitTest {
|
||||
@Test
|
||||
fun someTest() {
|
||||
commonMainExpect()
|
||||
CommonMain.invoke()
|
||||
AndroidMain.invoke()
|
||||
AndroidMain.invoke(ApplicationProvider.getApplicationContext())
|
||||
CommonTest().someTest()
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import okio.Path.Companion.toPath
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class AndroidUnitTestGermanFreeDebug {
|
||||
@Test
|
||||
fun someTest() {
|
||||
"".toPath()
|
||||
commonMainExpect()
|
||||
CommonMain.invoke()
|
||||
AndroidMain.invoke()
|
||||
AndroidMain.invoke(ApplicationProvider.getApplicationContext())
|
||||
CommonTest().someTest()
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
object CommonMain {
|
||||
operator fun invoke() = CommonMain
|
||||
}
|
||||
|
||||
expect fun commonMainExpect(): CommonMain
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import kotlin.test.Test
|
||||
|
||||
class CommonTest {
|
||||
@Test
|
||||
fun someTest() {
|
||||
commonMainExpect()
|
||||
CommonMain.invoke()
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
actual fun commonMainExpect(): CommonMain {
|
||||
return CommonMain.invoke()
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import org.junit.Test
|
||||
|
||||
class JvmTest {
|
||||
@Test
|
||||
fun someTest() {
|
||||
CommonMain.invoke()
|
||||
CommonTest().someTest()
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -34,7 +34,11 @@ internal object KotlinAndroidSourceSets {
|
||||
/* Ensures that each KotlinSourceSet only invokes the 'configurator' once */
|
||||
val configuredKotlinSourceSets = mutableSetOf<KotlinSourceSet>()
|
||||
|
||||
/* Hook eagerly into AndroidSourceSet creation */
|
||||
/*
|
||||
Hook eagerly into AndroidSourceSet creation
|
||||
Some 'base' source sets shall be created eagerly, as soon as available, too also
|
||||
make them available in the buildscript dsl immediately.
|
||||
*/
|
||||
android.sourceSets.all { androidSourceSet ->
|
||||
val kotlinSourceSetName = naming.kotlinSourceSetName(target.disambiguationClassifier, androidSourceSet.name) ?: return@all
|
||||
val kotlinSourceSet = kotlin.getOrCreateKotlinSourceSet(kotlinSourceSetName, androidSourceSet)
|
||||
|
||||
-15
@@ -35,21 +35,6 @@ internal fun KotlinAndroidSourceSetConfigurator(
|
||||
return CompositeKotlinAndroidSourceSetConfigurator(configurators.filterNotNull())
|
||||
}
|
||||
|
||||
internal operator fun KotlinAndroidSourceSetConfigurator.plus(
|
||||
other: KotlinAndroidSourceSetConfigurator
|
||||
): KotlinAndroidSourceSetConfigurator {
|
||||
val configurators = when {
|
||||
this is CompositeKotlinAndroidSourceSetConfigurator && other is CompositeKotlinAndroidSourceSetConfigurator ->
|
||||
this.configurators + other.configurators
|
||||
|
||||
this is CompositeKotlinAndroidSourceSetConfigurator -> this.configurators + other
|
||||
other is CompositeKotlinAndroidSourceSetConfigurator -> listOf(this) + other.configurators
|
||||
else -> listOf(this, other)
|
||||
}
|
||||
|
||||
return CompositeKotlinAndroidSourceSetConfigurator(configurators)
|
||||
}
|
||||
|
||||
private class CompositeKotlinAndroidSourceSetConfigurator(
|
||||
val configurators: List<KotlinAndroidSourceSetConfigurator>
|
||||
) : KotlinAndroidSourceSetConfigurator {
|
||||
|
||||
Reference in New Issue
Block a user