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