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 06701a55484..97f7b82b671 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
@@ -176,7 +176,7 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
val mavenPlugin = mavenProject.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID) ?: return
val compilerVersion = mavenPlugin.version ?: LanguageVersion.LATEST_STABLE.versionString
val kotlinFacet = module.getOrCreateFacet(modifiableModelsProvider, false)
- val platform = detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject)
+ val platform = detectPlatform(mavenProject)
kotlinFacet.configureFacet(compilerVersion, LanguageFeature.Coroutines.defaultState, platform, modifiableModelsProvider)
val configuredPlatform = kotlinFacet.configuration.settings.targetPlatformKind!!
@@ -190,8 +190,12 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
parseCompilerArgumentsToFacet(executionArguments, emptyList(), kotlinFacet, modifiableModelsProvider)
}
MavenProjectImportHandler.getInstances(module.project).forEach { it(kotlinFacet, mavenProject) }
+ setImplementedModuleName(kotlinFacet, mavenProject, module)
}
+ private fun detectPlatform(mavenProject: MavenProject) = detectPlatformByExecutions(mavenProject) ?:
+ detectPlatformByLibraries(mavenProject)
+
private fun detectPlatformByExecutions(mavenProject: MavenProject): TargetPlatformKind<*>? {
return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals }?.mapNotNull { goal ->
when (goal) {
@@ -254,6 +258,18 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
plugin.configurationElement.sourceDirectories().map { SourceType.PROD to it } +
plugin.executions.flatMap { execution -> execution.configurationElement.sourceDirectories().map { execution.sourceType() to it } }
}.distinct()
+
+ private fun setImplementedModuleName(kotlinFacet: KotlinFacet, mavenProject: MavenProject, module: Module) {
+ if (kotlinFacet.configuration.settings.targetPlatformKind == TargetPlatformKind.Common) {
+ kotlinFacet.configuration.settings.implementedModuleName = null
+ } else {
+ val manager = MavenProjectsManager.getInstance(module.project)
+ val mavenDependencies = mavenProject.dependencies.mapNotNull { manager?.findProject(it) }
+ val implemented = mavenDependencies.singleOrNull { detectPlatformByExecutions(it) == TargetPlatformKind.Common }
+
+ kotlinFacet.configuration.settings.implementedModuleName = implemented?.let { manager.findModule(it)?.name ?: it.displayName }
+ }
+ }
}
private fun MavenPlugin.isKotlinPlugin() = groupId == KotlinMavenImporter.KOTLIN_PLUGIN_GROUP_ID && artifactId == KotlinMavenImporter.KOTLIN_PLUGIN_ARTIFACT_ID
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 5e23446ca4d..51f2091ae1c 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
@@ -1726,6 +1726,193 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
}
}
+ fun testMultiModuleImport() {
+ createProjectSubDirs("src/main/kotlin", "my-common-module/src/main/kotlin", "my-jvm-module/src/main/kotlin", "my-js-module/src/main/kotlin")
+
+ val mainPom = createProjectPom("""
+ test
+ project
+ 1.0.0
+ pom
+
+
+ my-common-module
+ my-jvm-module
+ my-js-module
+
+
+
+ src/main/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ $kotlinVersion
+
+
+
+ """)
+
+ val commonModule = createModulePom(
+ "my-common-module",
+ """
+
+
+ test
+ project
+ 1.0.0
+
+
+ test
+ my-common-module
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-common
+ $kotlinVersion
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+
+ meta
+ compile
+
+ metadata
+
+
+
+
+
+
+ """
+ )
+
+ val jvmModule = createModulePom(
+ "my-jvm-module",
+ """
+
+
+ test
+ project
+ 1.0.0
+
+
+ test
+ my-jvm-module
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ $kotlinVersion
+
+
+ test
+ my-common-module
+ 1.0.0
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+
+ compile
+ compile
+
+ compile
+
+
+
+
+
+
+ """
+ )
+
+ val jsModule = createModulePom(
+ "my-js-module",
+ """
+
+
+ test
+ project
+ 1.0.0
+
+
+ test
+ my-js-module
+ 1.0.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-js
+ $kotlinVersion
+
+
+ test
+ my-common-module
+ 1.0.0
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+
+
+
+ js
+ compile
+
+ js
+
+
+
+
+
+
+ """
+ )
+
+ importProjects(mainPom, commonModule, jvmModule, jsModule)
+
+ assertModules("project", "my-common-module", "my-jvm-module", "my-js-module")
+ assertImporterStatePresent()
+
+ with (facetSettings("my-common-module")) {
+ Assert.assertEquals(TargetPlatformKind.Common.description, targetPlatformKind!!.description)
+ }
+
+ with (facetSettings("my-jvm-module")) {
+ Assert.assertEquals(TargetPlatformKind.Jvm(JvmTarget.JVM_1_6).description, targetPlatformKind!!.description)
+ Assert.assertEquals("my-common-module", implementedModuleName)
+ }
+
+ with (facetSettings("my-js-module")) {
+ Assert.assertEquals(TargetPlatformKind.JavaScript.description, targetPlatformKind!!.description)
+ Assert.assertEquals("my-common-module", implementedModuleName)
+ }
+ }
+
fun testJDKImport() {
object : WriteAction() {
override fun run(result: Result) {