diff --git a/plugins/allopen/allopen-ide/src/AllOpenMavenProjectImportHandler.kt b/plugins/allopen/allopen-ide/src/AllOpenMavenProjectImportHandler.kt index 6c3985d51a6..c552274ea2c 100644 --- a/plugins/allopen/allopen-ide/src/AllOpenMavenProjectImportHandler.kt +++ b/plugins/allopen/allopen-ide/src/AllOpenMavenProjectImportHandler.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.allopen.ide import org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler +import org.jetbrains.kotlin.utils.PathUtil class AllOpenMavenProjectImportHandler : AbstractMavenImportHandler() { private companion object { @@ -28,6 +29,7 @@ class AllOpenMavenProjectImportHandler : AbstractMavenImportHandler() { override val pluginName = "allopen" override val annotationOptionName = AllOpenCommandLineProcessor.ANNOTATION_OPTION.name override val mavenPluginArtifactName = "kotlin-maven-allopen" + override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().allOpenPluginJarPath override fun getAnnotations(enabledCompilerPlugins: List, compilerPluginOptions: List): List? { if ("all-open" !in enabledCompilerPlugins && "spring" !in enabledCompilerPlugins) { diff --git a/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractGradleImportHandler.kt b/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractGradleImportHandler.kt index b3d25328f56..343a80c9eb1 100644 --- a/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractGradleImportHandler.kt +++ b/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractGradleImportHandler.kt @@ -65,7 +65,8 @@ abstract class AbstractGradleImportHandler : GradleProjectImportHandler { val annotationFqNames = annotationFqNamesList.split(',') - // For now we can't use plugins from Gradle cause they're shaded. So we use ones from the IDEA plugin + // For now we can't use plugins from Gradle cause they're shaded and may have an incompatible version. + // So we use ones from the IDEA plugin. val classpath = listOf(pluginJarFileFromIdea.absolutePath) return AnnotationBasedCompilerPluginSetup(annotationFqNames, classpath) diff --git a/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractMavenImportHandler.kt b/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractMavenImportHandler.kt index 93be6d32aab..32d2dc0d119 100644 --- a/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractMavenImportHandler.kt +++ b/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractMavenImportHandler.kt @@ -30,6 +30,7 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler { abstract val pluginName: String abstract val annotationOptionName: String abstract val mavenPluginArtifactName: String + abstract val pluginJarFileFromIdea: File override fun invoke(facet: KotlinFacet, mavenProject: MavenProject) { modifyCompilerArgumentsForPlugin(facet, getPluginSetup(mavenProject), @@ -45,15 +46,6 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler { it.groupId == KOTLIN_PLUGIN_GROUP_ID && it.artifactId == KOTLIN_PLUGIN_ARTIFACT_ID } ?: return null - val runtimeJarFile = mavenProject.dependencies - .firstOrNull { it.groupId == KOTLIN_PLUGIN_GROUP_ID && - (it.artifactId == "kotlin-runtime" || it.artifactId == "kotlin-stdlib") } - ?.file ?: return null - val runtimeVersion = runtimeJarFile.parentFile.name - - val mavenCompilerPluginJar = File(runtimeJarFile.parentFile.parentFile.parentFile, - "$mavenPluginArtifactName/$runtimeVersion/$mavenPluginArtifactName-$runtimeVersion.jar") - val configuration = kotlinPlugin.configurationElement ?: return null val enabledCompilerPlugins = configuration.getElement("compilerPlugins") @@ -67,8 +59,11 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler { ?.mapTo(mutableListOf()) { (it as Text).text } ?: mutableListOf() + // We can't use the plugin from Gradle as it may have the incompatible version + val classpath = listOf(pluginJarFileFromIdea.absolutePath) + val annotationFqNames = getAnnotations(enabledCompilerPlugins, compilerPluginOptions) ?: return null - return AnnotationBasedCompilerPluginSetup(annotationFqNames, listOf(mavenCompilerPluginJar.absolutePath)) + return AnnotationBasedCompilerPluginSetup(annotationFqNames, classpath) } private fun Element.getElement(name: String) = content.firstOrNull { it is Element && it.name == name } as? Element diff --git a/plugins/noarg/noarg-ide/src/NoArgMavenProjectImportHandler.kt b/plugins/noarg/noarg-ide/src/NoArgMavenProjectImportHandler.kt index 84923b25105..4a2fb1f436a 100644 --- a/plugins/noarg/noarg-ide/src/NoArgMavenProjectImportHandler.kt +++ b/plugins/noarg/noarg-ide/src/NoArgMavenProjectImportHandler.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.noarg.ide import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler +import org.jetbrains.kotlin.utils.PathUtil class NoArgMavenProjectImportHandler : AbstractMavenImportHandler() { private companion object { @@ -28,6 +29,7 @@ class NoArgMavenProjectImportHandler : AbstractMavenImportHandler() { override val pluginName = "noarg" override val annotationOptionName = NoArgCommandLineProcessor.ANNOTATION_OPTION.name override val mavenPluginArtifactName = "kotlin-maven-noarg" + override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().noArgPluginJarPath override fun getAnnotations(enabledCompilerPlugins: List, compilerPluginOptions: List): List? { if ("no-arg" !in enabledCompilerPlugins && "jpa" !in enabledCompilerPlugins) {