diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt
index d3fde34a61f..ea0e24f7bad 100644
--- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt
+++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt
@@ -171,7 +171,7 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
PomFile.KotlinGoals.MetaData -> TargetPlatformKind.Common
else -> null
}
- }?.singleOrNull()
+ }?.distinct()?.singleOrNull()
}
private fun detectPlatformByLibraries(mavenProject: MavenProject): TargetPlatformKind<*>? {
diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt
index 2a3fe835cd6..2421e2ceeef 100644
--- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt
+++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.maven
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
+import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.KotlinFacetSettings
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.config.additionalArgumentsAsList
@@ -659,6 +660,564 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
}
}
+ fun testJvmDetectionByGoalWithJvmStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ compile
+
+
+
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind)
+ }
+
+ fun testJvmDetectionByGoalWithJsStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-js
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ compile
+
+
+
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind)
+ }
+
+ fun testJvmDetectionByGoalWithCommonStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-common
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ compile
+
+
+
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind)
+ }
+
+ fun testJsDetectionByGoalWithJvmStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ js
+
+
+
+ test-compile
+
+ test-js
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
+ }
+
+ fun testJsDetectionByGoalWithJsStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-js
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ js
+
+
+
+ test-compile
+
+ test-js
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
+ }
+
+ fun testJsDetectionByGoalWithCommonStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-common
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ js
+
+
+
+ test-compile
+
+ test-js
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
+ }
+
+ fun testCommonDetectionByGoalWithJvmStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ metadata
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
+ }
+
+ fun testCommonDetectionByGoalWithJsStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-js
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ metadata
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
+ }
+
+ fun testCommonDetectionByGoalWithCommonStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-common
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ metadata
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
+ }
+
+ fun testJvmDetectionByConflictingGoalsAndJvmStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ js
+
+
+
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind)
+ }
+
+ fun testJsDetectionByConflictingGoalsAndJsStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-js
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ js
+
+
+
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
+ }
+
+ fun testCommonDetectionByConflictingGoalsAndCommonStdlib() {
+ createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
+
+ importProject("""
+ test
+ project
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-common
+ 1.1.0
+
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+ compile
+
+ js
+
+
+
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+ """)
+
+ assertModules("project")
+ assertImporterStatePresent()
+
+ Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
+ }
+
private fun assertImporterStatePresent() {
assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java))
}