Redirect warning output to error log when allWarningsAsErrors is enabled
Issue #KT-35447 Fixed
This commit is contained in:
+2
-1
@@ -137,7 +137,8 @@ internal open class GradleCompilerRunner(protected val task: Task) {
|
||||
outputFiles = environment.outputFiles.toList(),
|
||||
taskPath = task.path,
|
||||
buildReportMode = environment.buildReportMode,
|
||||
kotlinScriptExtensions = environment.kotlinScriptExtensions
|
||||
kotlinScriptExtensions = environment.kotlinScriptExtensions,
|
||||
allWarningsAsErrors = compilerArgs.allWarningsAsErrors
|
||||
)
|
||||
TaskLoggers.put(task.path, task.logger)
|
||||
runCompilerAsync(workArgs)
|
||||
|
||||
+4
-2
@@ -56,7 +56,8 @@ internal class GradleKotlinCompilerWorkArguments(
|
||||
val outputFiles: List<File>,
|
||||
val taskPath: String,
|
||||
val buildReportMode: BuildReportMode?,
|
||||
val kotlinScriptExtensions: Array<String>
|
||||
val kotlinScriptExtensions: Array<String>,
|
||||
val allWarningsAsErrors: Boolean
|
||||
) : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 0
|
||||
@@ -95,6 +96,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
private val taskPath = config.taskPath
|
||||
private val buildReportMode = config.buildReportMode
|
||||
private val kotlinScriptExtensions = config.kotlinScriptExtensions
|
||||
private val allWarningsAsErrors = config.allWarningsAsErrors
|
||||
|
||||
private val log: KotlinLogger =
|
||||
TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it).apply { debug("Using '$taskPath' logger") } }
|
||||
@@ -113,7 +115,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
get() = incrementalCompilationEnvironment != null
|
||||
|
||||
override fun run() {
|
||||
val messageCollector = GradlePrintingMessageCollector(log)
|
||||
val messageCollector = GradlePrintingMessageCollector(log, allWarningsAsErrors)
|
||||
val exitCode = compileWithDaemonOrFallbackImpl(messageCollector)
|
||||
if (incrementalCompilationEnvironment?.disableMultiModuleIC == true) {
|
||||
incrementalCompilationEnvironment.multiModuleICSettings.buildHistoryFile.delete()
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ open class KaptWithKotlincTask : KaptTask(), CompilerArgumentAwareWithInput<K2JV
|
||||
|
||||
val args = prepareCompilerArguments()
|
||||
|
||||
val messageCollector = GradlePrintingMessageCollector(GradleKotlinLogger(logger))
|
||||
val messageCollector = GradlePrintingMessageCollector(GradleKotlinLogger(logger), args.allWarningsAsErrors)
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val environment = GradleCompilerEnvironment(
|
||||
compilerClasspath, messageCollector, outputItemCollector,
|
||||
|
||||
+10
-3
@@ -12,9 +12,12 @@ import org.jetbrains.kotlin.cli.common.messages.GradleStyleMessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinLogger
|
||||
|
||||
internal class GradlePrintingMessageCollector(val logger: KotlinLogger) :
|
||||
internal class GradlePrintingMessageCollector(
|
||||
val logger: KotlinLogger,
|
||||
private val allWarningsAsErrors: Boolean
|
||||
) :
|
||||
MessageCollector {
|
||||
constructor(logger: Logger) : this(GradleKotlinLogger(logger))
|
||||
constructor(logger: Logger, allWarningsAsErrors: Boolean) : this(GradleKotlinLogger(logger), allWarningsAsErrors)
|
||||
|
||||
private var hasErrors = false
|
||||
|
||||
@@ -38,7 +41,11 @@ internal class GradlePrintingMessageCollector(val logger: KotlinLogger) :
|
||||
|
||||
CompilerMessageSeverity.WARNING,
|
||||
CompilerMessageSeverity.STRONG_WARNING -> {
|
||||
logger.warn(renderedMessage)
|
||||
if (allWarningsAsErrors) {
|
||||
logger.error(renderedMessage)
|
||||
} else {
|
||||
logger.warn(renderedMessage)
|
||||
}
|
||||
}
|
||||
CompilerMessageSeverity.INFO -> {
|
||||
logger.info(renderedMessage)
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ open class KotlinCompileCommon : AbstractKotlinCompile<K2MetadataCompilerArgumen
|
||||
}
|
||||
|
||||
override fun callCompilerAsync(args: K2MetadataCompilerArguments, sourceRoots: SourceRoots, changedFiles: ChangedFiles) {
|
||||
val messageCollector = GradlePrintingMessageCollector(logger)
|
||||
val messageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner()
|
||||
val environment = GradleCompilerEnvironment(
|
||||
|
||||
+2
-2
@@ -401,7 +401,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
override fun callCompilerAsync(args: K2JVMCompilerArguments, sourceRoots: SourceRoots, changedFiles: ChangedFiles) {
|
||||
sourceRoots as SourceRoots.ForJvm
|
||||
|
||||
val messageCollector = GradlePrintingMessageCollector(logger)
|
||||
val messageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner()
|
||||
|
||||
@@ -622,7 +622,7 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
||||
|
||||
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
||||
|
||||
val messageCollector = GradlePrintingMessageCollector(logger)
|
||||
val messageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user