diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt index 252e39fad23..fd712efab18 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt @@ -83,5 +83,6 @@ interface CompilerArgumentAware : KotlinCompilerArgumen private val includedArgumentTypes = setOf( ArgumentType.Primitive, - ArgumentType.Classpath, + ArgumentType.PluginClasspath, + ArgumentType.DependencyClasspath, ) \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt index d32857b4a7e..7644752e843 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsDefault import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsHelper -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create import org.jetbrains.kotlin.gradle.report.BuildReportMode @@ -126,13 +125,15 @@ abstract class KaptGenerateStubsTask @Inject constructor( args.destinationAsFile = destinationDirectory.get().asFile } - classpath { args -> + pluginClasspath { args -> args.pluginClasspaths = runSafe { listOfNotNull( pluginClasspath, kotlinPluginData?.orNull?.classpath ).reduce(FileCollection::plus).toPathsArray() } + } + dependencyClasspath { args -> args.classpathAsList = runSafe { libraries.toList().filter { it.exists() } }.orEmpty() args.friendPaths = friendPaths.toPathsArray() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilerArgumentsProducer.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilerArgumentsProducer.kt index 2b97320b3f8..2922f3628f9 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilerArgumentsProducer.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilerArgumentsProducer.kt @@ -16,7 +16,8 @@ interface KotlinCompilerArgumentsProducer { enum class ArgumentType { Primitive, - Classpath, + PluginClasspath, + DependencyClasspath, Sources; companion object { @@ -40,7 +41,8 @@ interface KotlinCompilerArgumentsProducer { interface ContributeCompilerArgumentsContext { fun runSafe(action: () -> T): T? fun primitive(contribution: (args: T) -> Unit) - fun classpath(contribution: (args: T) -> Unit) + fun pluginClasspath(contribution: (args: T) -> Unit) + fun dependencyClasspath(contribution: (args: T) -> Unit) fun sources(contribution: (args: T) -> Unit) } @@ -99,8 +101,14 @@ private class CreateCompilerArgumentsContextImpl( } } - override fun classpath(contribution: (args: T) -> Unit) { - if (KotlinCompilerArgumentsProducer.ArgumentType.Classpath in includedArgumentTypes) { + override fun pluginClasspath(contribution: (args: T) -> Unit) { + if (KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath in includedArgumentTypes) { + applyContribution(contribution) + } + } + + override fun dependencyClasspath(contribution: (args: T) -> Unit) { + if (KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath in includedArgumentTypes) { applyContribution(contribution) } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/ide/IdeCompilerArgumentsResolverImpl.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/ide/IdeCompilerArgumentsResolverImpl.kt index 33425aa3b64..19a1d118fb7 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/ide/IdeCompilerArgumentsResolverImpl.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/ide/IdeCompilerArgumentsResolverImpl.kt @@ -32,7 +32,8 @@ internal class IdeCompilerArgumentsResolverImpl( isLenient = true, includeArgumentTypes = setOfNotNull( KotlinCompilerArgumentsProducer.ArgumentType.Primitive, - KotlinCompilerArgumentsProducer.ArgumentType.Classpath + KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath, + KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath .takeIf { extension !is KotlinMultiplatformExtension } .takeIf { producer is KotlinCompile } .takeIf { !extension.project.hasAndroidPlugin } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeLink.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeLink.kt index d7c0099a05a..05db5eada1a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeLink.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeLink.kt @@ -20,7 +20,6 @@ import org.gradle.process.ExecOperations import org.jetbrains.kotlin.cli.common.arguments.K2NativeCompilerArguments import org.jetbrains.kotlin.compilerRunner.* import org.jetbrains.kotlin.gradle.dsl.* -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider @@ -226,8 +225,11 @@ constructor( KotlinCommonCompilerToolOptionsHelper.fillCompilerArguments(toolOptions, args) } - classpath { args -> + pluginClasspath { args -> args.pluginClasspaths = compilerPlugins.flatMap { classpath -> runSafe { classpath.files } ?: emptySet() }.toPathsArray() + } + + dependencyClasspath { args -> args.libraries = runSafe { libraries.files.filterKlibsPassedToCompiler() }?.toPathsArray() args.exportedLibraries = runSafe { exportLibraries.files.filterKlibsPassedToCompiler() }?.toPathsArray() args.friendModules = runSafe { friendModule.files.toList().takeIf { it.isNotEmpty() } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt index a21854f350d..2bb481023d4 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated import org.jetbrains.kotlin.gradle.internal.isInIdeaSync import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create import org.jetbrains.kotlin.gradle.plugin.cocoapods.asValidFrameworkName @@ -454,9 +453,11 @@ internal constructor( KotlinNativeCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args) } - classpath { args -> + pluginClasspath { args -> args.pluginClasspaths = compilerPlugins.flatMap { classpath -> runSafe { classpath.files } ?: emptySet() }.toPathsArray() + } + dependencyClasspath { args -> args.libraries = runSafe { libraries.files.filterKlibsPassedToCompiler().toPathsArray() } args.friendModules = runSafe { friendModule.files.takeIf { it.isNotEmpty() }?.map { it.absolutePath }?.joinToString(File.pathSeparator) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Kotlin2JsCompile.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Kotlin2JsCompile.kt index 19e03ebfab2..5f2bfe713b6 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Kotlin2JsCompile.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Kotlin2JsCompile.kt @@ -167,13 +167,15 @@ abstract class Kotlin2JsCompile @Inject constructor( args.freeArgs = executionTimeFreeCompilerArgs ?: enhancedFreeCompilerArgs.get() } - classpath { args -> + pluginClasspath { args -> args.pluginClasspaths = runSafe { listOfNotNull( pluginClasspath, kotlinPluginData?.orNull?.classpath ).reduce(FileCollection::plus).toPathsArray() } + } + dependencyClasspath { args -> args.friendModules = friendDependencies.files.joinToString(File.pathSeparator) { it.absolutePath } args.libraries = runSafe { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompile.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompile.kt index 3007b6d4908..1411dc26615 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompile.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompile.kt @@ -245,13 +245,15 @@ abstract class KotlinCompile @Inject constructor( } } - classpath { args -> + pluginClasspath { args -> args.pluginClasspaths = runSafe { listOfNotNull( pluginClasspath, kotlinPluginData?.orNull?.classpath ).reduce(FileCollection::plus).toPathsArray() } + } + dependencyClasspath { args -> args.friendPaths = friendPaths.toPathsArray() args.classpathAsList = runSafe { libraries.toList().filter { it.exists() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt index 2a4e2e5d5da..563d6c2d12c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt @@ -23,7 +23,6 @@ import org.gradle.api.tasks.* import org.gradle.work.InputChanges import org.gradle.work.NormalizeLineEndings import org.gradle.workers.WorkerExecutor -import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl @@ -31,7 +30,6 @@ import org.jetbrains.kotlin.gradle.dsl.* import org.jetbrains.kotlin.gradle.internal.tasks.allOutputFiles import org.jetbrains.kotlin.gradle.logging.GradleErrorMessageCollector import org.jetbrains.kotlin.gradle.logging.GradlePrintingMessageCollector -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create import org.jetbrains.kotlin.gradle.report.BuildReportMode @@ -93,12 +91,15 @@ abstract class KotlinCompileCommon @Inject constructor( } } - classpath { args -> + pluginClasspath { args -> args.pluginClasspaths = runSafe { listOfNotNull( pluginClasspath, kotlinPluginData?.orNull?.classpath ).reduce(FileCollection::plus).toPathsArray() } + } + + dependencyClasspath { args -> args.classpath = runSafe { libraries.files.filter { it.exists() }.joinToString(File.pathSeparator) } args.friendPaths = runSafe { this@KotlinCompileCommon.friendPaths.files.toPathsArray() } args.refinesPaths = refinesMetadataPaths.toPathsArray()