Fix user-specified attributes in Android targets (KT-27714)
Ensure that custom target and compilation attributes are copied to relevant configurations of Android targets as well, which did not happen because of Android variants (and missing simple apiElements, runtimeElements) and Android compilations being created late in the project configuration. Issue #KT-27714 Fixed
This commit is contained in:
+64
@@ -196,7 +196,71 @@ class KotlinAndroid32GradleIT : KotlinAndroid3GradleIT(androidGradlePluginVersio
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCustomAttributesInAndroidTargets() = with(Project("new-mpp-android", GradleVersionRequired.AtLeast("4.7"))) {
|
||||
// Test the fix for KT-27714
|
||||
|
||||
setupWorkingDir()
|
||||
|
||||
// Enable publishing for all Android variants:
|
||||
gradleBuildScript("lib").appendText("\nkotlin.android('androidLib') { publishAllLibraryVariants() }")
|
||||
|
||||
val groupDir = "lib/build/repo/com/example/"
|
||||
|
||||
build("publish") {
|
||||
assertSuccessful()
|
||||
|
||||
// Also check that custom user-specified attributes are written in all Android modules metadata:
|
||||
assertFileContains(
|
||||
groupDir + "lib-androidlib/1.0/lib-androidlib-1.0.module",
|
||||
"\"com.example.target\": \"androidLib\"",
|
||||
"\"com.example.compilation\": \"release\""
|
||||
)
|
||||
assertFileContains(
|
||||
groupDir + "lib-androidlib-debug/1.0/lib-androidlib-debug-1.0.module",
|
||||
"\"com.example.target\": \"androidLib\"",
|
||||
"\"com.example.compilation\": \"debug\""
|
||||
)
|
||||
|
||||
projectDir.resolve(groupDir).deleteRecursively()
|
||||
}
|
||||
|
||||
// Check that the consumer side uses custom attributes specified in the target and compilations:
|
||||
run {
|
||||
val appBuildScriptBackup = gradleBuildScript("app").readText()
|
||||
|
||||
gradleBuildScript("app").appendText(
|
||||
"\n" + """
|
||||
kotlin.targets.androidApp.attributes.attribute(
|
||||
Attribute.of("com.example.target", String),
|
||||
"notAndroidLib"
|
||||
)
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build(":app:compileDebugKotlinAndroidApp") {
|
||||
assertFailed() // dependency resolution should fail
|
||||
assertContains("Required com.example.target 'notAndroidLib'")
|
||||
}
|
||||
|
||||
gradleBuildScript("app").writeText(
|
||||
appBuildScriptBackup + "\n" + """
|
||||
kotlin.targets.androidApp.compilations.all {
|
||||
attributes.attribute(
|
||||
Attribute.of("com.example.compilation", String),
|
||||
"notDebug"
|
||||
)
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build(":app:compileDebugKotlinAndroidApp") {
|
||||
assertFailed()
|
||||
assertContains("Required com.example.compilation 'notDebug'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+11
-1
@@ -66,7 +66,17 @@ kotlin {
|
||||
}
|
||||
|
||||
targets {
|
||||
fromPreset(presets.android, 'androidLib')
|
||||
fromPreset(presets.android, 'androidLib') {
|
||||
attributes {
|
||||
attribute(Attribute.of("com.example.target", String), "androidLib")
|
||||
}
|
||||
compilations.all {
|
||||
attributes {
|
||||
attribute(Attribute.of("com.example.compilation", String), compilationName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fromPreset(presets.jvm, 'jvmLib')
|
||||
fromPreset(presets.js, 'jsLib')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user