[MPP] [Android] implement testAndroidMultiplatformPublicationAGPCompatibility

This test publishes a Multiplatform/Android library locally with
a given AGP version (7.1-*+) and tests the compatibility with older
AGP consumer versions.

Two projects will be tested:

multiplatformAndroidConsumer:
kotlin("multiplatform") + android target depending on
the previous publication as 'commonMainImplementation' dependency

plainAndroidConsumer:
kotlin("android") depending on the previous publication
as 'implementation' dependency.

Both projects will test the 'assemble' umbrella task to ensure,
compatibility with the given publication.

^KT-49798 implicitly covered as well
This commit is contained in:
sebastian.sellmair
2021-11-19 13:59:40 +01:00
committed by Space
parent 8c5f980c16
commit 95018a9de0
16 changed files with 184 additions and 2 deletions
@@ -536,6 +536,51 @@ open class KotlinAndroid71GradleIT : KotlinAndroid70GradleIT() {
}
}
}
@Test
fun testAndroidMultiplatformPublicationAGPCompatibility() = with(Project("new-mpp-android-agp-compatibility")) {
/* Publish producer library with current version of AGP */
build(":producer:publishAllPublicationsToBuildDirRepository") {
assertSuccessful()
/* Check expected publication layout */
assertFileExists("build/repo/com/example/producer-android")
assertFileExists("build/repo/com/example/producer-android-debug")
assertFileExists("build/repo/com/example/producer-jvm")
}
val checkedConsumerAGPVersions = AGPVersion.testedVersions
// Special version added for testing KT-49798
.plus(AGPVersion.fromString("7.1.0-beta02"))
.filter { version -> version >= AGPVersion.v4_2_0 }
checkedConsumerAGPVersions.forEach { agpVersion ->
this.setupWorkingDir()
println("Testing compatibility for AGP consumer version $agpVersion")
val buildOptions = defaultBuildOptions().copy(androidGradlePluginVersion = agpVersion)
/*
Project: multiplatformAndroidConsumer is a mpp project with jvm and android targets.
This project depends on the previous publication as 'commonMainImplementation' dependency
*/
build(":multiplatformAndroidConsumer:assemble", options = buildOptions) {
assertSuccessful(
"multiplatformAndroidConsumer build failed with consumer agpVersion $agpVersion (Producer: $androidGradlePluginVersion)"
)
}
/*
Project: plainAndroidConsumer only uses the 'kotlin("android")' plugin
This project depends on the previous publication as 'implementation' dependency
*/
build(":plainAndroidConsumer:assemble", options = buildOptions) {
assertSuccessful(
"plainAndroidConsumer build failed with consumer agpVersion $agpVersion (Producer: $androidGradlePluginVersion)"
)
}
}
}
}
open class KotlinAndroid34GradleIT : KotlinAndroid3GradleIT() {
@@ -455,11 +455,12 @@ abstract class BaseGradleIT {
return model
}
fun CompiledProject.assertSuccessful() {
fun CompiledProject.assertSuccessful(message: String? = null) {
if (resultCode == 0) return
val errors = "(?m)^.*\\[ERROR] \\[\\S+] (.*)$".toRegex().findAll(output)
val errorMessage = buildString {
if (message != null) appendLine(message)
appendLine("Gradle build failed")
appendLine()
if (errors.any()) {
@@ -979,4 +980,4 @@ Finished executing task ':$taskName'|
fun BaseGradleIT.BuildOptions.withFreeCommandLineArgument(argument: String) = copy(
freeCommandLineArgs = freeCommandLineArgs + argument
)
)
@@ -24,5 +24,7 @@ class AGPVersion private constructor(private val versionNumber: VersionNumber) {
val v4_2_0 = fromString("4.2.0")
val v7_0_0 = fromString("7.0.0-beta02")
val v7_1_0 = fromString("7.1.0-beta03")
val testedVersions = listOf(v3_4_1, v3_6_0, v4_1_0, v4_2_0, v7_0_0, v7_1_0)
}
}
@@ -0,0 +1,11 @@
allprojects {
repositories {
mavenLocal()
mavenCentral()
google()
}
}
tasks.register<Delete>("clean") {
delete(buildDir)
}
@@ -0,0 +1,4 @@
kotlin.code.style=official
kotlin.js.generate.executable.default=false
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
@@ -0,0 +1,21 @@
plugins {
id("com.android.library")
kotlin("multiplatform")
}
repositories {
maven(rootProject.buildDir.resolve("repo"))
mavenCentral()
}
android {
compileSdkVersion(30)
}
kotlin {
android()
sourceSets.commonMain.get().dependencies {
implementation("com.example:producer:1.0.0-SNAPSHOT")
}
}
@@ -0,0 +1,7 @@
@file:Suppress("unused")
object MultiplatformAndroidConsumerCommonMain {
init {
println(ProducerCommonMain)
}
}
@@ -0,0 +1,7 @@
@file:Suppress("unused")
object MultiplatformAndroidConsumerMain {
init {
println(ProducerCommonMain)
}
}
@@ -0,0 +1,18 @@
plugins {
id("com.android.library")
kotlin("android")
}
android {
compileSdkVersion(30)
}
repositories {
maven(rootProject.buildDir.resolve("repo"))
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk7"))
implementation("com.example:producer:1.0.0-SNAPSHOT")
}
@@ -0,0 +1,7 @@
@file:Suppress("unused")
object PlainAndroidConsumer {
init {
println(ProducerCommonMain)
}
}
@@ -0,0 +1,27 @@
val kotlin_version: String by extra
plugins {
`maven-publish`
id("com.android.library")
kotlin("multiplatform")
}
group = "com.example"
version = "1.0.0-SNAPSHOT"
publishing {
repositories {
maven(rootProject.buildDir.resolve("repo")) {
name = "buildDir"
}
}
}
android {
compileSdkVersion(30)
}
kotlin {
jvm()
android { publishAllLibraryVariants() }
}
@@ -0,0 +1,28 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
google()
}
val kotlin_version: String? by settings
val android_tools_version: String? by settings
plugins {
kotlin("multiplatform").version(kotlin_version)
kotlin("android").version(kotlin_version)
}
resolutionStrategy {
eachPlugin {
if (requested.id.id.startsWith("com.android")) {
useModule("com.android.tools.build:gradle:$android_tools_version")
}
}
}
}
include(":producer")
include(":plainAndroidConsumer")
include(":multiplatformAndroidConsumer")