diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index 82009dbf64b..111bfaea650 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -275,6 +275,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { ) var friendPaths: Array? by FreezableVar(null) + @Argument( + value = "-Xallow-no-source-files", + description = "Allow no source files" + ) + var allowNoSourceFiles: Boolean by FreezableVar(false) + override fun configureAnalysisFlags(collector: MessageCollector): MutableMap, Any> { val result = super.configureAnalysisFlags(collector) result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index 8d267d4f554..0560ce1a585 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -80,10 +80,7 @@ class K2JVMCompiler : CLICompiler() { configuration.configureExplicitContentRoots(arguments) configuration.configureStandardLibs(paths, arguments) - // in case of IC we need to run compiler even - // when there are no files to compile (to update caches & metadata when a file is removed) - val isICEnabled = configuration[JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS] != null - if (arguments.buildFile == null && arguments.freeArgs.isEmpty() && !(arguments.version || isICEnabled)) { + if (arguments.buildFile == null && arguments.freeArgs.isEmpty() && !arguments.version && !arguments.allowNoSourceFiles) { if (arguments.script) { messageCollector.report(ERROR, "Specify script source path to evaluate") return COMPILATION_ERROR @@ -154,7 +151,7 @@ class K2JVMCompiler : CLICompiler() { if (!it) return COMPILATION_ERROR } - if (environment.getSourceFiles().isEmpty() && !isICEnabled && buildFile == null) { + if (environment.getSourceFiles().isEmpty() && !arguments.allowNoSourceFiles && buildFile == null) { if (arguments.version) return OK messageCollector.report(ERROR, "No source files") diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt index 02de4dab98b..5d7aa0a7825 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt @@ -368,6 +368,7 @@ class IncrementalJvmCompilerRunner( val compiler = K2JVMCompiler() val freeArgsBackup = args.freeArgs.toList() args.freeArgs += sourcesToCompile.map { it.absolutePath } + args.allowNoSourceFiles = true val exitCode = compiler.exec(messageCollector, services, args) args.freeArgs = freeArgsBackup return exitCode diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index e01f6fb4551..7f572b3cbbb 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -2,6 +2,7 @@ Usage: kotlinc-jvm where advanced options include: -Xadd-modules= Root modules to resolve in addition to the initial modules, or all modules on the module path if is ALL-MODULE-PATH + -Xallow-no-source-files Allow no source files -Xassertions={always-enable|always-disable|jvm|legacy} Assert calls behaviour -Xassertions=always-enable: enable, ignore jvm assertion settings; 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 d95db0b3f8b..63f9c102f6e 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 @@ -405,6 +405,7 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl if (defaultsOnly) return + args.allowNoSourceFiles = true args.classpathAsList = compileClasspath.toList() args.destinationAsFile = destinationDir parentKotlinOptionsImpl?.updateArguments(args)