diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt index a4e0fd9f561..df0820ee413 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt @@ -989,6 +989,17 @@ class GradleFacetImportTest : GradleImportingTestCase() { TestCase.assertEquals("1.1", holder.settings.languageVersion) } + @Ignore //TODO enable this test after the Kotlin gradle plugin with required fixes is released + @Test + fun testImportCompilerArgumentsWithInvalidDependencies() { + configureByFiles() + importProject() + with(facetSettings("project_main")) { + Assert.assertEquals("1.8", (mergedCompilerArguments as K2JVMCompilerArguments).jvmTarget) + } + + } + private fun checkStableModuleName(projectName: String, expectedName: String, platform: TargetPlatform, isProduction: Boolean) { val module = getModule(projectName) val moduleInfo = if (isProduction) module.productionSourceInfo() else module.testSourceInfo() diff --git a/idea/kotlin-gradle-tooling/src/KotlinGradleModelBuilder.kt b/idea/kotlin-gradle-tooling/src/KotlinGradleModelBuilder.kt index 85c092b9525..b236fc10293 100644 --- a/idea/kotlin-gradle-tooling/src/KotlinGradleModelBuilder.kt +++ b/idea/kotlin-gradle-tooling/src/KotlinGradleModelBuilder.kt @@ -123,12 +123,12 @@ class KotlinGradleModelBuilder : AbstractKotlinGradleModelBuilder() { private fun Project.pathOrName() = if (path == ":") name else path @Suppress("UNCHECKED_CAST") - private fun Task.getCompilerArguments(methodName: String): List { + private fun Task.getCompilerArguments(methodName: String): List? { return try { javaClass.getDeclaredMethod(methodName).invoke(this) as List } catch (e: Exception) { // No argument accessor method is available - emptyList() + null } } @@ -175,7 +175,8 @@ class KotlinGradleModelBuilder : AbstractKotlinGradleModelBuilder() { val sourceSetName = compileTask.getSourceSetName() val currentArguments = compileTask.getCompilerArguments("getSerializedCompilerArguments") - val defaultArguments = compileTask.getCompilerArguments("getDefaultSerializedCompilerArguments") + ?: compileTask.getCompilerArguments("getSerializedCompilerArgumentsIgnoreClasspathIssues") ?: emptyList() + val defaultArguments = compileTask.getCompilerArguments("getDefaultSerializedCompilerArguments").orEmpty() val dependencyClasspath = compileTask.getDependencyClasspath() compilerArgumentsBySourceSet[sourceSetName] = ArgsInfoImpl(currentArguments, defaultArguments, dependencyClasspath) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt index e15f2933616..8a20c15db96 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt @@ -25,6 +25,9 @@ interface CompilerArgumentAware { val serializedCompilerArguments: List get() = ArgumentUtils.convertArgumentsToStringList(prepareCompilerArguments()) + val serializedCompilerArgumentsIgnoreClasspathIssues: List + get() = ArgumentUtils.convertArgumentsToStringList(prepareCompilerArguments(ignoreClasspathResolutionErrors = true)) + val defaultSerializedCompilerArguments: List get() = createCompilerArgs() .also { setupCompilerArgs(it, defaultsOnly = true) } @@ -34,11 +37,11 @@ interface CompilerArgumentAware { get() = CompilerArgumentsGradleInput.createInputsMap(prepareCompilerArguments()) fun createCompilerArgs(): T - fun setupCompilerArgs(args: T, defaultsOnly: Boolean = false) + fun setupCompilerArgs(args: T, defaultsOnly: Boolean = false, ignoreClasspathResolutionErrors: Boolean = false) } -internal fun CompilerArgumentAware.prepareCompilerArguments() = - createCompilerArgs().also { setupCompilerArgs(it) } +internal fun CompilerArgumentAware.prepareCompilerArguments(ignoreClasspathResolutionErrors: Boolean = false) = + createCompilerArgs().also { setupCompilerArgs(it, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) } interface CompilerArgumentAwareWithInput : CompilerArgumentAware { @get:Internal diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt index 58144b1b20b..2b0dd2917fe 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt @@ -84,8 +84,8 @@ open class KaptGenerateStubsTask : KotlinCompile() { !stubsDir.isParentOf(source) && !generatedSourcesDir.isParentOf(source) - override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean) { - kotlinCompileTask.setupCompilerArgs(args) + override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { + kotlinCompileTask.setupCompilerArgs(args, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) val pluginOptionsWithKapt = pluginOptions.withWrappedKaptOptions(withApClasspath = kaptClasspath) args.pluginOptions = (pluginOptionsWithKapt.arguments + args.pluginOptions!!).toTypedArray() diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithKotlincTask.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithKotlincTask.kt index 74db041d8f6..705cf091e5e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithKotlincTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithKotlincTask.kt @@ -46,8 +46,8 @@ open class KaptWithKotlincTask : KaptTask(), CompilerArgumentAwareWithInput = findKotlinMetadataCompilerClasspath(project) - override fun setupCompilerArgs(args: K2MetadataCompilerArguments, defaultsOnly: Boolean) { + override fun setupCompilerArgs(args: K2MetadataCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { args.apply { fillDefaultValues() } - super.setupCompilerArgs(args, defaultsOnly) + super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) args.moduleName = friendTask?.moduleName ?: this@KotlinCompileCommon.moduleName diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinJsDce.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinJsDce.kt index df72a11a7c4..e94eb1fdad0 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinJsDce.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinJsDce.kt @@ -43,7 +43,7 @@ import java.io.File override fun createCompilerArgs(): K2JSDceArguments = K2JSDceArguments() - override fun setupCompilerArgs(args: K2JSDceArguments, defaultsOnly: Boolean) { + override fun setupCompilerArgs(args: K2JSDceArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { dceOptionsImpl.updateArguments(args) args.declarationsToKeep = keep.toTypedArray() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index 63f9c102f6e..a2c71356b88 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -325,7 +325,7 @@ abstract class AbstractKotlinCompile() : AbstractKo */ internal abstract fun callCompilerAsync(args: T, sourceRoots: SourceRoots, changedFiles: ChangedFiles) - override fun setupCompilerArgs(args: T, defaultsOnly: Boolean) { + override fun setupCompilerArgs(args: T, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { args.coroutinesState = when (coroutines) { Coroutines.ENABLE -> CommonCompilerArguments.ENABLE Coroutines.WARN -> CommonCompilerArguments.WARN @@ -393,9 +393,9 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl override fun createCompilerArgs(): K2JVMCompilerArguments = K2JVMCompilerArguments() - override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean) { + override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { args.apply { fillDefaultValues() } - super.setupCompilerArgs(args, defaultsOnly) + super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) args.moduleName = friendTask?.moduleName ?: moduleName logger.kotlinDebug { "args.moduleName = ${args.moduleName}" } @@ -406,7 +406,11 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl if (defaultsOnly) return args.allowNoSourceFiles = true - args.classpathAsList = compileClasspath.toList() + args.classpathAsList = try { + compileClasspath.toList() + } catch (e: Exception) { + if (ignoreClasspathResolutionErrors) emptyList() else throw(e) + } args.destinationAsFile = destinationDir parentKotlinOptionsImpl?.updateArguments(args) kotlinOptionsImpl.updateArguments(args) @@ -539,9 +543,9 @@ open class Kotlin2JsCompile : AbstractKotlinCompile(), Ko override fun createCompilerArgs(): K2JSCompilerArguments = K2JSCompilerArguments() - override fun setupCompilerArgs(args: K2JSCompilerArguments, defaultsOnly: Boolean) { + override fun setupCompilerArgs(args: K2JSCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { args.apply { fillDefaultValues() } - super.setupCompilerArgs(args, defaultsOnly) + super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) args.outputFile = outputFile.canonicalPath