Fix Android Lint dependency resolution issues (KT-49483)
Android Gradle plugin resolves the *Classpath configurations in an artifact view with an artifactType attribute set, which should give a resolved variant with a different `org.gradle.category` attribute. With `org.gradle.category=library` set by the Kotlin Gradle plugin, that couldn't work. To fix this, don't set the `org.gradle.category` attribute on the Android resolvable configurations. TODO: Add integration tests!
This commit is contained in:
+48
-1
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.gradle
|
|||||||
import org.gradle.api.logging.LogLevel
|
import org.gradle.api.logging.LogLevel
|
||||||
import org.gradle.api.logging.configuration.WarningMode
|
import org.gradle.api.logging.configuration.WarningMode
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
|
||||||
import org.jetbrains.kotlin.gradle.tooling.BuildKotlinToolingMetadataTask
|
import org.jetbrains.kotlin.gradle.tooling.BuildKotlinToolingMetadataTask
|
||||||
import org.jetbrains.kotlin.gradle.util.*
|
import org.jetbrains.kotlin.gradle.util.*
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||||
@@ -466,7 +467,7 @@ open class KotlinAndroid70GradleIT : KotlinAndroid36GradleIT() {
|
|||||||
get() = GradleVersionRequired.AtLeast("7.0")
|
get() = GradleVersionRequired.AtLeast("7.0")
|
||||||
|
|
||||||
override fun defaultBuildOptions(): BuildOptions {
|
override fun defaultBuildOptions(): BuildOptions {
|
||||||
val javaHome = File("/opt/openjdk-bin-11")
|
val javaHome = File(System.getProperty("jdk11Home") ?: error("jdk11Home not specified"))
|
||||||
Assume.assumeTrue("JDK 11 should be available", javaHome.isDirectory)
|
Assume.assumeTrue("JDK 11 should be available", javaHome.isDirectory)
|
||||||
return super.defaultBuildOptions().copy(javaHome = javaHome, warningMode = WarningMode.Summary)
|
return super.defaultBuildOptions().copy(javaHome = javaHome, warningMode = WarningMode.Summary)
|
||||||
}
|
}
|
||||||
@@ -1043,6 +1044,52 @@ fun getSomething() = 10
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testLintDependencyResolutionKt49483() = with(Project("AndroidProject")) {
|
||||||
|
setupWorkingDir()
|
||||||
|
|
||||||
|
gradleBuildScript().modify {
|
||||||
|
"""
|
||||||
|
plugins {
|
||||||
|
id("com.android.lint")
|
||||||
|
}
|
||||||
|
|
||||||
|
""".trimIndent() + it
|
||||||
|
}
|
||||||
|
|
||||||
|
gradleBuildScript("Lib").appendText("\n" + """
|
||||||
|
android {
|
||||||
|
lintOptions.checkDependencies = true
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":java-lib"))
|
||||||
|
}
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
gradleSettingsScript().appendText(
|
||||||
|
"\n" + """
|
||||||
|
include("java-lib")
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
with(projectDir.resolve("java-lib/build.gradle.kts")) {
|
||||||
|
ensureParentDirsCreated()
|
||||||
|
writeText(
|
||||||
|
"""
|
||||||
|
plugins {
|
||||||
|
id("java-library")
|
||||||
|
id("com.android.lint")
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
build(":Lib:lintFlavor1Debug") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertNotContains("as an external dependency and not analyze it.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun jvmToAndroidModifier(
|
private fun jvmToAndroidModifier(
|
||||||
appendKotlinVersion: Boolean = false
|
appendKotlinVersion: Boolean = false
|
||||||
): (String) -> CharSequence = { line ->
|
): (String) -> CharSequence = { line ->
|
||||||
|
|||||||
+1
-4
@@ -14,10 +14,7 @@ pluginManagement {
|
|||||||
|
|
||||||
resolutionStrategy {
|
resolutionStrategy {
|
||||||
eachPlugin {
|
eachPlugin {
|
||||||
if (requested.id.id == "com.android.application" ||
|
if (requested.id.id.startsWith("com.android.")) {
|
||||||
requested.id.id == "com.android.library" ||
|
|
||||||
requested.id.id == "com.android.feature" ||
|
|
||||||
requested.id.id == "com.android.test") {
|
|
||||||
useModule("com.android.tools.build:gradle:$android_tools_version")
|
useModule("com.android.tools.build:gradle:$android_tools_version")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -329,7 +329,9 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
|
|||||||
isVisible = false
|
isVisible = false
|
||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
attributes.attribute(USAGE_ATTRIBUTE, KotlinUsages.consumerApiUsage(compilation.target))
|
attributes.attribute(USAGE_ATTRIBUTE, KotlinUsages.consumerApiUsage(compilation.target))
|
||||||
attributes.attribute(Category.CATEGORY_ATTRIBUTE, project.categoryByName(Category.LIBRARY))
|
if (compilation.platformType != KotlinPlatformType.androidJvm) {
|
||||||
|
attributes.attribute(Category.CATEGORY_ATTRIBUTE, project.categoryByName(Category.LIBRARY))
|
||||||
|
}
|
||||||
description = "Compile classpath for $compilation."
|
description = "Compile classpath for $compilation."
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +361,9 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
|
|||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
isCanBeResolved = true
|
isCanBeResolved = true
|
||||||
attributes.attribute(USAGE_ATTRIBUTE, KotlinUsages.consumerRuntimeUsage(compilation.target))
|
attributes.attribute(USAGE_ATTRIBUTE, KotlinUsages.consumerRuntimeUsage(compilation.target))
|
||||||
attributes.attribute(Category.CATEGORY_ATTRIBUTE, project.categoryByName(Category.LIBRARY))
|
if (compilation.platformType != KotlinPlatformType.androidJvm) {
|
||||||
|
attributes.attribute(Category.CATEGORY_ATTRIBUTE, project.categoryByName(Category.LIBRARY))
|
||||||
|
}
|
||||||
description = "Runtime classpath of $compilation."
|
description = "Runtime classpath of $compilation."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user