@@ -4,6 +4,7 @@ import org.gradle.api.*
4
4
import org.gradle.api.artifacts.dsl.*
5
5
import org.gradle.api.tasks.testing.Test
6
6
import org.gradle.kotlin.dsl.*
7
+ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
7
8
import java.net.*
8
9
import java.util.logging.*
9
10
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
@@ -147,3 +148,36 @@ fun shouldUseLocalMaven(project: Project): Boolean {
147
148
}
148
149
return hasSnapshotDependency || isSnapshotTrainEnabled(project)
149
150
}
151
+
152
+ /* *
153
+ * Returns a non-null value if the CI needs to override the default behavior of treating warnings as errors.
154
+ * Then, `true` means that warnings should be treated as errors, `false` means that they should not.
155
+ */
156
+ private fun warningsAreErrorsOverride (project : Project ): Boolean? =
157
+ when (val prop = project.rootProject.properties[" kotlin_Werror_override" ] as ? String ) {
158
+ null -> null
159
+ " enable" -> true
160
+ " disable" -> false
161
+ else -> error(" Unknown value for 'kotlin_Werror_override': $prop " )
162
+ }
163
+
164
+ /* *
165
+ * Set warnings as errors, but allow the Kotlin User Project configuration to take over. See KT-75078.
166
+ */
167
+ fun KotlinCommonCompilerOptions.setWarningsAsErrors (project : Project ) {
168
+ if (warningsAreErrorsOverride(project) != false ) {
169
+ allWarningsAsErrors = true
170
+ } else {
171
+ freeCompilerArgs.addAll(" -Wextra" , " -Xuse-fir-experimental-checkers" )
172
+ }
173
+ }
174
+
175
+ /* *
176
+ * Compiler flags required of Kotlin User Projects. See KT-75078.
177
+ */
178
+ fun KotlinCommonCompilerOptions.configureKotlinUserProject () {
179
+ freeCompilerArgs.addAll(
180
+ " -Xreport-all-warnings" , // emit warnings even if there are also errors
181
+ " -Xrender-internal-diagnostic-names" , // render the diagnostic names in CLI
182
+ )
183
+ }
0 commit comments