Gradle Support: Do not create facet for module without kotlin plugin
#KT-17265 Fixed
This commit is contained in:
@@ -31,6 +31,7 @@ import kotlin.collections.HashSet
|
||||
typealias CompilerArgumentsBySourceSet = Map<String, List<String>>
|
||||
|
||||
interface KotlinGradleModel : Serializable {
|
||||
val hasKotlinPlugin: Boolean
|
||||
val currentCompilerArgumentsBySourceSet: CompilerArgumentsBySourceSet
|
||||
val defaultCompilerArgumentsBySourceSet: CompilerArgumentsBySourceSet
|
||||
val coroutines: String?
|
||||
@@ -39,6 +40,7 @@ interface KotlinGradleModel : Serializable {
|
||||
}
|
||||
|
||||
class KotlinGradleModelImpl(
|
||||
override val hasKotlinPlugin: Boolean,
|
||||
override val currentCompilerArgumentsBySourceSet: CompilerArgumentsBySourceSet,
|
||||
override val defaultCompilerArgumentsBySourceSet: CompilerArgumentsBySourceSet,
|
||||
override val coroutines: String?,
|
||||
@@ -55,6 +57,7 @@ class KotlinGradleModelBuilder : ModelBuilderService {
|
||||
"kotlin" to "kotlin-platform-jvm",
|
||||
"kotlin2js" to "kotlin-platform-js"
|
||||
)
|
||||
val kotlinPluginIds = listOf("kotlin", "kotlin2js")
|
||||
private val kotlinPlatformCommonPluginId = "kotlin-platform-common"
|
||||
}
|
||||
|
||||
@@ -151,6 +154,9 @@ class KotlinGradleModelBuilder : ModelBuilderService {
|
||||
}
|
||||
|
||||
override fun buildAll(modelName: String?, project: Project): KotlinGradleModelImpl {
|
||||
val kotlinPluginId = kotlinPluginIds.singleOrNull { project.plugins.findPlugin(it) != null }
|
||||
val platformPluginId = platformPluginIds.singleOrNull { project.plugins.findPlugin(it) != null }
|
||||
|
||||
val currentCompilerArgumentsBySourceSet = LinkedHashMap<String, List<String>>()
|
||||
val defaultCompilerArgumentsBySourceSet = LinkedHashMap<String, List<String>>()
|
||||
|
||||
@@ -161,11 +167,11 @@ class KotlinGradleModelBuilder : ModelBuilderService {
|
||||
collectCompilerArguments(compileTask, "getDefaultSerializedCompilerArguments", defaultCompilerArgumentsBySourceSet)
|
||||
}
|
||||
|
||||
val platform = platformPluginIds.singleOrNull { project.plugins.findPlugin(it) != null }
|
||||
?: pluginToPlatform.entries.singleOrNull { project.plugins.findPlugin(it.key) != null }?.value
|
||||
val platform = platformPluginId ?: pluginToPlatform.entries.singleOrNull { project.plugins.findPlugin(it.key) != null }?.value
|
||||
val transitiveCommon = getImplements(project)?.let { transitiveCommonDependencies(it) } ?: emptySet()
|
||||
|
||||
return KotlinGradleModelImpl(
|
||||
kotlinPluginId != null || platformPluginId != null,
|
||||
currentCompilerArgumentsBySourceSet,
|
||||
defaultCompilerArgumentsBySourceSet,
|
||||
getCoroutines(project),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSFrameworkSupportProvider"/>
|
||||
<pluginDescriptions implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradlePluginDescription"/>
|
||||
<projectResolve implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleProjectResolverExtension"/>
|
||||
<projectResolve implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleProjectResolverExtension" order="first"/>
|
||||
</extensions>
|
||||
|
||||
<extensionPoints>
|
||||
|
||||
+4
@@ -28,12 +28,15 @@ import org.gradle.tooling.model.idea.IdeaModule
|
||||
import org.jetbrains.kotlin.gradle.CompilerArgumentsBySourceSet
|
||||
import org.jetbrains.kotlin.gradle.KotlinGradleModel
|
||||
import org.jetbrains.kotlin.gradle.KotlinGradleModelBuilder
|
||||
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
|
||||
import org.jetbrains.kotlin.psi.UserDataProperty
|
||||
import org.jetbrains.plugins.gradle.model.ExternalProject
|
||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
|
||||
import org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil.getModuleId
|
||||
|
||||
var DataNode<ModuleData>.hasKotlinPlugin
|
||||
by NotNullableUserDataProperty(Key.create<Boolean>("HAS_KOTLIN_PLUGIN"), false)
|
||||
var DataNode<ModuleData>.currentCompilerArgumentsBySourceSet
|
||||
by UserDataProperty(Key.create<CompilerArgumentsBySourceSet>("CURRENT_COMPILER_ARGUMENTS"))
|
||||
var DataNode<ModuleData>.defaultCompilerArgumentsBySourceSet
|
||||
@@ -67,6 +70,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
|
||||
}
|
||||
}
|
||||
|
||||
ideModule.hasKotlinPlugin = gradleModel.hasKotlinPlugin
|
||||
ideModule.currentCompilerArgumentsBySourceSet = gradleModel.currentCompilerArgumentsBySourceSet
|
||||
ideModule.defaultCompilerArgumentsBySourceSet = gradleModel.defaultCompilerArgumentsBySourceSet
|
||||
ideModule.coroutines = gradleModel.coroutines
|
||||
|
||||
@@ -109,6 +109,11 @@ private fun configureFacetByGradleModule(
|
||||
ideModule: Module,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
): KotlinFacet? {
|
||||
if (!moduleNode.hasKotlinPlugin) {
|
||||
KotlinFacet.get(ideModule)?.let { modelsProvider.getModifiableFacetModel(ideModule).removeFacet(it) }
|
||||
return null
|
||||
}
|
||||
|
||||
val compilerVersion = moduleNode.findAll(BuildScriptClasspathData.KEY).firstOrNull()?.data?.let(::findKotlinPluginVersion)
|
||||
?: return null
|
||||
val platformKind = detectPlatformByPlugin(moduleNode) ?: detectPlatformByLibrary(moduleNode)
|
||||
|
||||
@@ -748,4 +748,64 @@ class GradleFacetImportTest : GradleImportingTestCase() {
|
||||
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoFacetInModuleWithoutKotlinPlugin() {
|
||||
createProjectSubFile("build.gradle", """
|
||||
group 'gr01'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.1"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1"
|
||||
}
|
||||
""")
|
||||
createProjectSubFile("settings.gradle", """
|
||||
rootProject.name = 'gr01'
|
||||
include 'm1'
|
||||
""")
|
||||
createProjectSubFile("m1/build.gradle", """
|
||||
group 'gr01'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
apply plugin: 'java'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
}
|
||||
""")
|
||||
importProject()
|
||||
|
||||
Assert.assertNotNull(KotlinFacet.get(getModule("gr01_main")))
|
||||
Assert.assertNotNull(KotlinFacet.get(getModule("gr01_test")))
|
||||
Assert.assertNull(KotlinFacet.get(getModule("m1_main")))
|
||||
Assert.assertNull(KotlinFacet.get(getModule("m1_test")))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user