Check that kotlin-reflect has a correct version during resolution
After we migrated to the binary reflect in previous commits we want to
make sure that people won't accidentaly depend on wrong reflect in the
future.
diff --git a/build.gradle.kts b/build.gradle.kts
index 4158306..ef22fc1 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -387,10 +387,46 @@
val ignoreTestFailures by extra(project.kotlinBuildProperties.ignoreTestFailures)
+val dependencyOnSnapshotReflectWhitelist = setOf(
+ ":kotlin-compiler",
+ ":tools:binary-compatibility-validator",
+ ":tools:kotlin-stdlib-gen",
+)
+
allprojects {
if (!project.path.startsWith(":kotlin-ide.")) {
pluginManager.apply("common-configuration")
}
+ configurations.all {
+ resolutionStrategy.eachDependency {
+ // Javadoc publishing adds dokka dependencies that have transitive dependencies on stdlib and reflect
+ if (requested.group != "org.jetbrains.kotlin" || kotlinBuildProperties.publishGradlePluginsJavadoc) {
+ return@eachDependency
+ }
+ val expectedReflectVersion = commonDependencyVersion("org.jetbrains.kotlin", "kotlin-reflect")
+ if (requested.name == "kotlin-reflect" && project.path !in dependencyOnSnapshotReflectWhitelist) {
+ check(requested.version == expectedReflectVersion) {
+ """
+ 'kotlin-reflect' should have '$expectedReflectVersion' version. But it was '${requested.version}'
+ Suggestions:
+ 1. Use 'commonDependency("org.jetbrains.kotlin:kotlin-reflect") { isTransitive = false }'
+ 2. Avoid 'kotlin-reflect' leakage from transitive dependencies with 'exclude("org.jetbrains.kotlin")'
+ """.trimIndent()
+ }
+ }
+ if (requested.name.startsWith("kotlin-stdlib")) {
+ check(requested.version != expectedReflectVersion) {
+ """
+ '${requested.name}' has a wrong version. It's not allowed to be '$expectedReflectVersion'
+ Suggestions:
+ 1. Most likely, it leaked from 'kotlin-reflect' transitive dependencies. Use 'isTransitive = false' for
+ 'kotlin-reflect' dependencies
+ 2. Avoid '${requested.name}' leakage from other transitive dependencies with 'exclude("org.jetbrains.kotlin")'
+ """.trimIndent()
+ }
+ }
+ }
+ }
val mirrorRepo: String? = findProperty("maven.repository.mirror")?.toString()
repositories {
diff --git a/compiler/ir/ir.tree/tree-generator/build.gradle.kts b/compiler/ir/ir.tree/tree-generator/build.gradle.kts
index 41446a8..83ab626 100644
--- a/compiler/ir/ir.tree/tree-generator/build.gradle.kts
+++ b/compiler/ir/ir.tree/tree-generator/build.gradle.kts
@@ -13,7 +13,9 @@
dependencies {
implementation(project(":generators"))
implementation(project(":core:compiler.common"))
- implementation("com.squareup:kotlinpoet:1.11.0")
+ implementation("com.squareup:kotlinpoet:1.11.0") {
+ exclude("org.jetbrains.kotlin")
+ }
compileOnly(intellijCore())
compileOnly(commonDependency("org.jetbrains.intellij.deps:trove4j"))
diff --git a/compiler/tests-mutes/tc-integration/build.gradle.kts b/compiler/tests-mutes/tc-integration/build.gradle.kts
index 83e6146..fcc4c08 100644
--- a/compiler/tests-mutes/tc-integration/build.gradle.kts
+++ b/compiler/tests-mutes/tc-integration/build.gradle.kts
@@ -7,8 +7,12 @@
dependencies {
api(kotlinStdlib())
implementation(project(":compiler:tests-mutes"))
- implementation("khttp:khttp:1.0.0")
- implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.0")
+ implementation("khttp:khttp:1.0.0") {
+ exclude("org.jetbrains.kotlin")
+ }
+ implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.0") {
+ exclude("org.jetbrains.kotlin")
+ }
}
sourceSets {
diff --git a/kotlin-native/backend.native/build.gradle b/kotlin-native/backend.native/build.gradle
index 9e63989..8f5245e 100644
--- a/kotlin-native/backend.native/build.gradle
+++ b/kotlin-native/backend.native/build.gradle
@@ -108,7 +108,9 @@
kotlin_compiler_jar project(kotlinCompilerModule)
kotlin_stdlib_jar kotlinStdLibModule
use(DependenciesKt) {
- kotlin_reflect_jar commonDependency("org.jetbrains.kotlin:kotlin-reflect")
+ kotlin_reflect_jar(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) {
+ transitive = false
+ }
}
kotlin_script_runtime_jar project(":kotlin-script-runtime")
diff --git a/kotlin-native/build-tools/build.gradle.kts b/kotlin-native/build-tools/build.gradle.kts
index 765b137..f5ee5c9 100644
--- a/kotlin-native/build-tools/build.gradle.kts
+++ b/kotlin-native/build-tools/build.gradle.kts
@@ -14,6 +14,14 @@
id("gradle-plugin-dependency-configuration")
}
+configurations.all {
+ // The `exclude` fixes: 'kotlin-reflect' should have '1.6.10' version. But it was '1.5.31'
+ // Technically, this should avoid kotlin-reflect leakage added by `kotlin-dsl` plugin, but it looks like it doesn't work because
+ // I can still see that kotlin-reflect 1.5.31 is in runtime dependencies of the module (I wrote a `main` function which checks
+ // reflect at runtime). IDK how to fix it properly.
+ exclude("org.jetbrains.kotlin", "kotlin-reflect")
+}
+
buildscript {
val rootBuildDirectory by extra(project.file("../.."))
diff --git a/kotlin-native/shared/build.gradle.kts b/kotlin-native/shared/build.gradle.kts
index 90d1379..1896365 100644
--- a/kotlin-native/shared/build.gradle.kts
+++ b/kotlin-native/shared/build.gradle.kts
@@ -49,7 +49,9 @@
}
dependencies {
- kotlinCompilerClasspath("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
+ kotlinCompilerClasspath("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion") {
+ exclude("org.jetbrains.kotlin", "kotlin-reflect")
+ }
implementation(kotlinStdlib())
implementation(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts
index d98129b..588718d 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts
@@ -65,9 +65,15 @@
testImplementation(project(":kotlin-android-extensions"))
testImplementation(project(":kotlin-parcelize-compiler"))
testImplementation(commonDependency("org.jetbrains.intellij.deps", "trove4j"))
- testImplementation(commonDependency("io.ktor", "ktor-server-test-host"))
- testImplementation(commonDependency("io.ktor", "ktor-server-core"))
- testImplementation(commonDependency("io.ktor", "ktor-server-netty"))
+ testImplementation(commonDependency("io.ktor", "ktor-server-test-host")) {
+ exclude("org.jetbrains.kotlin")
+ }
+ testImplementation(commonDependency("io.ktor", "ktor-server-core")) {
+ exclude("org.jetbrains.kotlin")
+ }
+ testImplementation(commonDependency("io.ktor", "ktor-server-netty")) {
+ exclude("org.jetbrains.kotlin")
+ }
testImplementation(commonDependency("io.ktor", "ktor-client-mock"))
testImplementation(gradleApi())
diff --git a/libraries/tools/kotlin-gradle-plugin/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin/build.gradle.kts
index 381a3be..3b93f79 100644
--- a/libraries/tools/kotlin-gradle-plugin/build.gradle.kts
+++ b/libraries/tools/kotlin-gradle-plugin/build.gradle.kts
@@ -47,9 +47,14 @@
commonCompileOnly(project(":kotlin-scripting-compiler"))
commonCompileOnly(project(":kotlin-gradle-statistics"))
commonCompileOnly(project(":kotlin-gradle-build-metrics"))
- commonCompileOnly("com.android.tools.build:gradle:3.6.4")
+ commonCompileOnly(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
+ commonCompileOnly("com.android.tools.build:gradle:3.6.4") {
+ exclude("org.jetbrains.kotlin")
+ }
commonCompileOnly("com.android.tools.build:gradle-api:3.6.4")
- commonCompileOnly("com.android.tools.build:builder:3.6.4")
+ commonCompileOnly("com.android.tools.build:builder:3.6.4") {
+ exclude("org.jetbrains.kotlin")
+ }
commonCompileOnly("com.android.tools.build:builder-model:3.6.4")
commonCompileOnly("org.codehaus.groovy:groovy-all:2.4.12")
commonCompileOnly(intellijCore())
@@ -90,7 +95,9 @@
if (!kotlinBuildProperties.isInJpsBuildIdeaSync) {
val functionalTestImplementation by configurations.getting
- functionalTestImplementation("com.android.tools.build:gradle:7.2.1")
+ functionalTestImplementation("com.android.tools.build:gradle:7.2.1") {
+ exclude("org.jetbrains.kotlin")
+ }
functionalTestImplementation("com.android.tools.build:gradle-api:7.2.1")
functionalTestImplementation(gradleKotlinDsl())
functionalTestImplementation(project(":kotlin-gradle-plugin-kpm-android"))