[MPP] Disambiguate compilation and source set configurations
Add 'compilation' postfix to configuration names of compilations. This is necessary to distinguish them from source set ones. Without the change, default source sets of test compilations and the test compilations themselves have the same name. For instance, jvmTestImplementation was interpreted as a configuration for a source set jvmTest and a compilation with the same name. This leads to incorrect configuration hierarchies and unexpected dependencies in them. KT-35916 KT-49877
This commit is contained in:
committed by
Space
parent
f91ea4b4d9
commit
69bb85f71f
+4
-4
@@ -163,10 +163,10 @@ class VariantAwareDependenciesMppIT : BaseGradleIT() {
|
||||
gradleBuildScript().appendText(
|
||||
"\n" + """
|
||||
dependencies {
|
||||
jvm6Implementation project(':${innerJvmProject.projectName}')
|
||||
jvm6TestRuntimeOnly project(':${innerJvmProject.projectName}')
|
||||
nodeJsImplementation project(':${innerJsProject.projectName}')
|
||||
nodeJsTestRuntimeOnly project(':${innerJsProject.projectName}')
|
||||
jvm6CompilationImplementation project(':${innerJvmProject.projectName}')
|
||||
jvm6TestCompilationRuntimeOnly project(':${innerJvmProject.projectName}')
|
||||
nodeJsCompilationImplementation project(':${innerJsProject.projectName}')
|
||||
nodeJsTestCompilationRuntimeOnly project(':${innerJsProject.projectName}')
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
+3
-3
@@ -20,9 +20,9 @@ kotlin.targets.fromPreset(kotlin.presets.js, 'browser') {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
browserImplementation project(":libraryProject")
|
||||
browserImplementation "org.jetbrains.kotlin:kotlin-stdlib-js"
|
||||
browserImplementation "org.mozilla:rhino:1.7.7.1"
|
||||
browserCompilationImplementation project(":libraryProject")
|
||||
browserCompilationImplementation "org.jetbrains.kotlin:kotlin-stdlib-js"
|
||||
browserCompilationImplementation "org.mozilla:rhino:1.7.7.1"
|
||||
}
|
||||
|
||||
tasks.named('compileKotlinBrowser') {
|
||||
|
||||
+2
@@ -96,6 +96,7 @@ open class DefaultCompilationDetails<T : KotlinCommonOptions>(
|
||||
lowerCamelCaseName(
|
||||
target.disambiguationClassifier,
|
||||
compilationPurpose.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
||||
"compilation",
|
||||
)
|
||||
)
|
||||
|
||||
@@ -592,6 +593,7 @@ internal open class JsCompilationDetails(
|
||||
return lowerCamelCaseName(
|
||||
disambiguationClassifierInPlatform,
|
||||
compilationPurpose.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
||||
"compilation",
|
||||
simpleName
|
||||
)
|
||||
}
|
||||
|
||||
+66
-2
@@ -10,12 +10,14 @@ package org.jetbrains.kotlin.gradle
|
||||
import org.gradle.api.attributes.Category
|
||||
import org.gradle.api.attributes.Usage
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.mpp.buildProjectWithMPP
|
||||
import org.jetbrains.kotlin.gradle.mpp.kotlin
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.targets
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
||||
@@ -145,10 +147,72 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
with(project.evaluate()) {
|
||||
assertContainsDependencies("jsApi", "test:compilation-dependency", "test:source-set-dependency")
|
||||
|
||||
project.evaluate()
|
||||
|
||||
with(project) {
|
||||
assertContainsDependencies("jsCompilationApi", "test:compilation-dependency", "test:source-set-dependency")
|
||||
assertContainsDependencies("jsMainApi", "test:source-set-dependency")
|
||||
assertNotContainsDependencies("jsMainApi", "test:compilation-dependency")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test compilation and source set configurations don't clash`() {
|
||||
val project = buildProjectWithMPP {
|
||||
kotlin {
|
||||
jvm()
|
||||
js(BOTH)
|
||||
linuxX64("linux")
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
project.kotlinExtension.targets.flatMap { it.compilations }.forEach { compilation ->
|
||||
val compilationSourceSets = compilation.allKotlinSourceSets
|
||||
val compilationConfigurationNames = compilation.relatedConfigurationNames
|
||||
val sourceSetConfigurationNames = compilationSourceSets.flatMapTo(mutableSetOf()) { it.relatedConfigurationNames }
|
||||
|
||||
assert(compilationConfigurationNames.none { it in sourceSetConfigurationNames }) {
|
||||
"""A name clash between source set and compilation configurations detected for the following configurations:
|
||||
|${compilationConfigurationNames.filter { it in sourceSetConfigurationNames }.joinToString()}
|
||||
""".trimMargin()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test scoped sourceSet's configurations don't extend other configurations`() {
|
||||
val project = buildProjectWithMPP {
|
||||
kotlin {
|
||||
jvm()
|
||||
js(BOTH)
|
||||
linuxX64("linux")
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
for (sourceSet in project.kotlinExtension.sourceSets) {
|
||||
val configurationNames = listOf(
|
||||
sourceSet.implementationConfigurationName,
|
||||
sourceSet.apiConfigurationName,
|
||||
sourceSet.compileOnlyConfigurationName,
|
||||
sourceSet.runtimeOnlyConfigurationName,
|
||||
)
|
||||
|
||||
for (name in configurationNames) {
|
||||
val extendsFrom = project.configurations.getByName(name).extendsFrom
|
||||
assert(extendsFrom.isEmpty()) {
|
||||
"Configuration $name is not expected to be extending anything, but it extends: ${
|
||||
extendsFrom.joinToString(
|
||||
prefix = "[",
|
||||
postfix = "]"
|
||||
) { it.name }
|
||||
}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user