MPP: Assign TEST scope to dependencies of test source sets
#KT-26868 Fixed
This commit is contained in:
+16
@@ -14,6 +14,9 @@ import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjec
|
|||||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.roots.DependencyScope
|
||||||
|
import com.intellij.openapi.roots.ExportableOrderEntry
|
||||||
|
import com.intellij.openapi.roots.ModifiableRootModel
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||||
import org.jetbrains.kotlin.config.CoroutineSupport
|
import org.jetbrains.kotlin.config.CoroutineSupport
|
||||||
import org.jetbrains.kotlin.config.JvmTarget
|
import org.jetbrains.kotlin.config.JvmTarget
|
||||||
@@ -59,9 +62,22 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
|
|||||||
}
|
}
|
||||||
|
|
||||||
configureFacet(sourceSetData, kotlinSourceSet, mainModuleData, ideModule, modelsProvider)
|
configureFacet(sourceSetData, kotlinSourceSet, mainModuleData, ideModule, modelsProvider)
|
||||||
|
|
||||||
|
if (kotlinSourceSet.isTestModule) {
|
||||||
|
assignTestScope(rootModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun assignTestScope(rootModel: ModifiableRootModel) {
|
||||||
|
rootModel
|
||||||
|
.orderEntries
|
||||||
|
.asSequence()
|
||||||
|
.filterIsInstance<ExportableOrderEntry>()
|
||||||
|
.filter { it.scope == DependencyScope.COMPILE }
|
||||||
|
.forEach { it.scope = DependencyScope.TEST }
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val KotlinModule.kind
|
private val KotlinModule.kind
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
|
|||||||
+37
-37
@@ -139,9 +139,9 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
module("app_commonTest") {
|
module("app_commonTest") {
|
||||||
platform(CommonIdePlatformKind.Platform)
|
platform(CommonIdePlatformKind.Platform)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonMain", DependencyScope.COMPILE)
|
moduleDependency("lib_commonMain", DependencyScope.TEST)
|
||||||
moduleDependency("app_commonMain", DependencyScope.COMPILE)
|
moduleDependency("app_commonMain", DependencyScope.TEST)
|
||||||
sourceFolder("app/src/commonTest/kotlin", KotlinSourceRootType.TestSource)
|
sourceFolder("app/src/commonTest/kotlin", KotlinSourceRootType.TestSource)
|
||||||
sourceFolder("app/src/commonTest/resources", KotlinResourceRootType.TestResource)
|
sourceFolder("app/src/commonTest/resources", KotlinResourceRootType.TestResource)
|
||||||
inheritProjectOutput()
|
inheritProjectOutput()
|
||||||
@@ -159,13 +159,13 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
module("app_jsTest") {
|
module("app_jsTest") {
|
||||||
platform(JsIdePlatformKind.Platform)
|
platform(JsIdePlatformKind.Platform)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.TEST)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.TEST)
|
||||||
moduleDependency("lib_jsMain", DependencyScope.COMPILE)
|
moduleDependency("lib_jsMain", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonMain", DependencyScope.COMPILE)
|
moduleDependency("lib_commonMain", DependencyScope.TEST)
|
||||||
moduleDependency("app_commonMain", DependencyScope.COMPILE)
|
moduleDependency("app_commonMain", DependencyScope.TEST)
|
||||||
moduleDependency("app_commonTest", DependencyScope.COMPILE)
|
moduleDependency("app_commonTest", DependencyScope.TEST)
|
||||||
moduleDependency("app_jsMain", DependencyScope.COMPILE)
|
moduleDependency("app_jsMain", DependencyScope.TEST)
|
||||||
sourceFolder("app/src/jsTest/kotlin", KotlinSourceRootType.TestSource)
|
sourceFolder("app/src/jsTest/kotlin", KotlinSourceRootType.TestSource)
|
||||||
sourceFolder("app/src/jsTest/resources", KotlinResourceRootType.TestResource)
|
sourceFolder("app/src/jsTest/resources", KotlinResourceRootType.TestResource)
|
||||||
outputPath("app/build/classes/kotlin/js/test", false)
|
outputPath("app/build/classes/kotlin/js/test", false)
|
||||||
@@ -185,15 +185,15 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
module("app_jvmTest") {
|
module("app_jvmTest") {
|
||||||
platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6))
|
platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6))
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.TEST)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.TEST)
|
||||||
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.TEST)
|
||||||
moduleDependency("lib_jvmMain", DependencyScope.COMPILE)
|
moduleDependency("lib_jvmMain", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonMain", DependencyScope.COMPILE)
|
moduleDependency("lib_commonMain", DependencyScope.TEST)
|
||||||
moduleDependency("app_test", DependencyScope.COMPILE)
|
moduleDependency("app_test", DependencyScope.TEST)
|
||||||
moduleDependency("app_jvmMain", DependencyScope.COMPILE)
|
moduleDependency("app_jvmMain", DependencyScope.TEST)
|
||||||
moduleDependency("app_commonMain", DependencyScope.COMPILE)
|
moduleDependency("app_commonMain", DependencyScope.TEST)
|
||||||
moduleDependency("app_commonTest", DependencyScope.COMPILE)
|
moduleDependency("app_commonTest", DependencyScope.TEST)
|
||||||
sourceFolder("app/src/jvmTest/kotlin", JavaSourceRootType.TEST_SOURCE)
|
sourceFolder("app/src/jvmTest/kotlin", JavaSourceRootType.TEST_SOURCE)
|
||||||
sourceFolder("app/src/jvmTest/resources", JavaResourceRootType.TEST_RESOURCE)
|
sourceFolder("app/src/jvmTest/resources", JavaResourceRootType.TEST_RESOURCE)
|
||||||
outputPath("app/build/classes/kotlin/jvm/test", false)
|
outputPath("app/build/classes/kotlin/jvm/test", false)
|
||||||
@@ -211,11 +211,11 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
module("app_test") {
|
module("app_test") {
|
||||||
platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8))
|
platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8))
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.TEST)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.TEST)
|
||||||
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonMain", DependencyScope.COMPILE)
|
moduleDependency("lib_commonMain", DependencyScope.TEST)
|
||||||
moduleDependency("app_main", DependencyScope.COMPILE)
|
moduleDependency("app_main", DependencyScope.TEST)
|
||||||
sourceFolder("app/src/test/java", JavaSourceRootType.TEST_SOURCE)
|
sourceFolder("app/src/test/java", JavaSourceRootType.TEST_SOURCE)
|
||||||
sourceFolder("app/src/test/kotlin", JavaSourceRootType.TEST_SOURCE)
|
sourceFolder("app/src/test/kotlin", JavaSourceRootType.TEST_SOURCE)
|
||||||
sourceFolder("app/src/test/resources", JavaResourceRootType.TEST_RESOURCE)
|
sourceFolder("app/src/test/resources", JavaResourceRootType.TEST_RESOURCE)
|
||||||
@@ -231,8 +231,8 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
module("lib_commonTest") {
|
module("lib_commonTest") {
|
||||||
platform(CommonIdePlatformKind.Platform)
|
platform(CommonIdePlatformKind.Platform)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonMain", DependencyScope.COMPILE)
|
moduleDependency("lib_commonMain", DependencyScope.TEST)
|
||||||
sourceFolder("lib/src/commonTest/kotlin", KotlinSourceRootType.TestSource)
|
sourceFolder("lib/src/commonTest/kotlin", KotlinSourceRootType.TestSource)
|
||||||
sourceFolder("lib/src/commonTest/resources", KotlinResourceRootType.TestResource)
|
sourceFolder("lib/src/commonTest/resources", KotlinResourceRootType.TestResource)
|
||||||
inheritProjectOutput()
|
inheritProjectOutput()
|
||||||
@@ -248,11 +248,11 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
module("lib_jsTest") {
|
module("lib_jsTest") {
|
||||||
platform(JsIdePlatformKind.Platform)
|
platform(JsIdePlatformKind.Platform)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.TEST)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonMain", DependencyScope.COMPILE)
|
moduleDependency("lib_commonMain", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonTest", DependencyScope.COMPILE)
|
moduleDependency("lib_commonTest", DependencyScope.TEST)
|
||||||
moduleDependency("lib_jsMain", DependencyScope.COMPILE)
|
moduleDependency("lib_jsMain", DependencyScope.TEST)
|
||||||
sourceFolder("lib/src/jsTest/kotlin", KotlinSourceRootType.TestSource)
|
sourceFolder("lib/src/jsTest/kotlin", KotlinSourceRootType.TestSource)
|
||||||
sourceFolder("lib/src/jsTest/resources", KotlinResourceRootType.TestResource)
|
sourceFolder("lib/src/jsTest/resources", KotlinResourceRootType.TestResource)
|
||||||
outputPath("lib/build/classes/kotlin/js/test", false)
|
outputPath("lib/build/classes/kotlin/js/test", false)
|
||||||
@@ -269,12 +269,12 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
module("lib_jvmTest") {
|
module("lib_jvmTest") {
|
||||||
platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6))
|
platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6))
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.TEST)
|
||||||
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.TEST)
|
||||||
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
|
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonTest", DependencyScope.COMPILE)
|
moduleDependency("lib_commonTest", DependencyScope.TEST)
|
||||||
moduleDependency("lib_commonMain", DependencyScope.COMPILE)
|
moduleDependency("lib_commonMain", DependencyScope.TEST)
|
||||||
moduleDependency("lib_jvmMain", DependencyScope.COMPILE)
|
moduleDependency("lib_jvmMain", DependencyScope.TEST)
|
||||||
sourceFolder("lib/src/jvmTest/kotlin", JavaSourceRootType.TEST_SOURCE)
|
sourceFolder("lib/src/jvmTest/kotlin", JavaSourceRootType.TEST_SOURCE)
|
||||||
sourceFolder("lib/src/jvmTest/resources", JavaResourceRootType.TEST_RESOURCE)
|
sourceFolder("lib/src/jvmTest/resources", JavaResourceRootType.TEST_RESOURCE)
|
||||||
outputPath("lib/build/classes/kotlin/jvm/test", false)
|
outputPath("lib/build/classes/kotlin/jvm/test", false)
|
||||||
|
|||||||
Reference in New Issue
Block a user