Skip to content

Commit ae357a9

Browse files
TapchicomaAbduqodiri Qurbonzoda
andauthored
K1 dev warning as errors cherry-pick (#2950)
* Remove deprecated APIs usage and enable warning-as-errors for build scripts (#2925) * Fix deprecated URL constructor usage in build scripts. * Enable warnings-as-errors for build scripts This should force to update build scripts on any new deprecation introduced in the used plugins. * Fix deprecation waring in teamcity-conventions.gradle.kts * Suppress deprecation in native-targets-conventions.gradle.kts * Use proper OptIn annotation in source-sets-conventions.gradle.kts * Fix deprecation warnings in Java9Modularity.kt * Suppress deprecation introduced in Kotlin 2.1.20 release. Should be migrated once this project will start using Kotlin 2.1.20 by default. * Enable warnings-as-errors for build logic compilation This should force to update scripts on new deprecation introduced in the plugins. * Enable warnings-as-errors for integration-tests project build scripts * Remove deprecated 'kotlin.js.compiler' property Only IR compiler available now. * fixup! Remove deprecated APIs usage and enable warning-as-errors for build scripts (#2925) * Drop usage of deprecated Any?.freeze() in K/N target (#2819) The legacy memory model was removed from the K/N runtime in 1.9.20. Now, this function does nothing, and its usages can be safely dropped. Worker.execute functions no longer require the argument to be frozen, as objects can no longer be frozen. * Update KLib API dumps * Update yarn lock * Better approach to override language version This allows propagating it to all sourcesets including shared one. * Update to Gradle 8.7 in integration-test * Update to Kotlin 2.1.0 in integration test * Update yarn lock in integration-test --------- Co-authored-by: Abduqodiri Qurbonzoda <[email protected]>
1 parent cf0c152 commit ae357a9

32 files changed

+348
-465
lines changed

benchmark/build.gradle.kts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ tasks.assemble {
4242
tasks.withType<KotlinCompile>().configureEach {
4343
compilerOptions {
4444
jvmTarget = JvmTarget.JVM_1_8
45-
}
46-
47-
kotlinOptions {
4845
if (overriddenLanguageVersion != null) {
49-
languageVersion = overriddenLanguageVersion
50-
freeCompilerArgs += "-Xsuppress-version-warnings"
46+
languageVersion = KotlinVersion.fromVersion(overriddenLanguageVersion!!)
47+
freeCompilerArgs.add("-Xsuppress-version-warnings")
5148
}
5249
}
5350
}

bom/build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ publishing {
3737
forEach { pub ->
3838
pub as DefaultMavenPublication
3939
pub.unsetModuleDescriptorGenerator()
40-
tasks.matching { it.name == "generateMetadataFileFor${pub.name.capitalize()}Publication" }.all {
41-
onlyIf { false }
40+
41+
tasks.configureEach {
42+
if (name == "generateMetadataFileFor${pub.name.capitalizeCompat()}Publication") {
43+
onlyIf { false }
44+
}
4245
}
4346
}
4447
}

build.gradle.kts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import kotlinx.validation.*
66
import org.jetbrains.dokka.gradle.*
7+
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
78

89
plugins {
910
base
@@ -157,10 +158,8 @@ tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstall
157158
args.add("--ignore-engines")
158159
}
159160

160-
// == compiler version setup ==
161-
gradle.taskGraph.whenReady {
162-
println("Using Kotlin compiler version: ${org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION}")
163-
}
161+
// == KGP version setup ==
162+
logger.warn("Project is using Kotlin Gradle plugin version: ${project.getKotlinPluginVersion()}")
164163

165164
// == projects lists and flags ==
166165
// getters are required because of variable lazy initialization in Gradle

buildSrc/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ repositories {
3737
mavenLocal()
3838
}
3939

40+
kotlin {
41+
compilerOptions {
42+
allWarningsAsErrors = true
43+
}
44+
}
45+
4046
dependencies {
4147
implementation(libs.gradlePlugin.kotlin)
4248
implementation(libs.gradlePlugin.kover)

buildSrc/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.kotlin.dsl.allWarningsAsErrors=true

buildSrc/src/main/kotlin/Java9Modularity.kt

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.gradle.*
1616
import org.jetbrains.kotlin.gradle.dsl.*
1717
import org.jetbrains.kotlin.gradle.plugin.*
1818
import org.jetbrains.kotlin.gradle.plugin.mpp.*
19-
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.*
2019
import org.jetbrains.kotlin.gradle.targets.jvm.*
2120
import org.jetbrains.kotlin.gradle.tasks.*
2221
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -27,6 +26,13 @@ import kotlin.reflect.*
2726
import kotlin.reflect.full.*
2827

2928
object Java9Modularity {
29+
private val KotlinProjectExtension.targets: Iterable<KotlinTarget>
30+
get() = when (this) {
31+
is KotlinSingleTargetExtension<*> -> listOf(this.target)
32+
is KotlinMultiplatformExtension -> targets
33+
else -> error("Unexpected 'kotlin' extension $this")
34+
}
35+
3036

3137
@JvmStatic
3238
@JvmOverloads
@@ -49,16 +55,19 @@ object Java9Modularity {
4955
}
5056

5157
target.compilations.forEach { compilation ->
52-
val compileKotlinTask = compilation.compileKotlinTask as KotlinCompile
58+
@Suppress("UNCHECKED_CAST")
59+
val compileKotlinTask = compilation.compileTaskProvider as TaskProvider<KotlinCompile>
5360
val defaultSourceSet = compilation.defaultSourceSet
5461

5562
// derive the names of the source set and compile module task
5663
val sourceSetName = defaultSourceSet.name + "Module"
5764

5865
kotlin.sourceSets.create(sourceSetName) {
5966
val sourceFile = this.kotlin.find { it.name == "module-info.java" }
60-
val targetDirectory = compileKotlinTask.destinationDirectory.map {
61-
it.dir("../${it.asFile.name}Module")
67+
val targetDirectory = compileKotlinTask.flatMap { task ->
68+
task.destinationDirectory.map {
69+
it.dir("../${it.asFile.name}Module")
70+
}
6271
}
6372

6473
// only configure the compilation if necessary
@@ -109,37 +118,38 @@ object Java9Modularity {
109118
* but it currently won't compile to a module-info.class file.
110119
*/
111120
private fun Project.registerVerifyModuleTask(
112-
compileTask: KotlinCompile,
121+
compileTask: TaskProvider<KotlinCompile>,
113122
sourceFile: File
114123
): TaskProvider<out KotlinJvmCompile> {
115124
apply<KotlinApiPlugin>()
116-
val verifyModuleTaskName = "verify${compileTask.name.removePrefix("compile").capitalize()}Module"
125+
val verifyModuleTaskName = "verify${compileTask.name.removePrefix("compile").capitalizeCompat()}Module"
117126
// work-around for https://youtrack.jetbrains.com/issue/KT-60542
118127
val kotlinApiPlugin = plugins.getPlugin(KotlinApiPlugin::class)
119128
val verifyModuleTask = kotlinApiPlugin.registerKotlinJvmCompileTask(
120129
verifyModuleTaskName,
121-
compileTask.compilerOptions.moduleName.get()
130+
compilerOptions = compileTask.get().compilerOptions,
131+
explicitApiMode = provider { ExplicitApiMode.Disabled }
122132
)
123133
verifyModuleTask {
124134
group = VERIFICATION_GROUP
125135
description = "Verify Kotlin sources for JPMS problems"
126-
libraries.from(compileTask.libraries)
127-
source(compileTask.sources)
128-
source(compileTask.javaSources)
136+
libraries.from(compileTask.map { it.libraries })
137+
source(compileTask.map { it.sources })
138+
source(compileTask.map { it.javaSources })
129139
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
130-
@Suppress("INVISIBLE_MEMBER")
131-
source(compileTask.scriptSources)
140+
source(compileTask.map {
141+
@Suppress("INVISIBLE_MEMBER")
142+
it.scriptSources
143+
})
132144
source(sourceFile)
133145
destinationDirectory.set(temporaryDir)
134-
multiPlatformEnabled.set(compileTask.multiPlatformEnabled)
146+
multiPlatformEnabled.set(compileTask.get().multiPlatformEnabled)
135147
compilerOptions {
136148
jvmTarget.set(JvmTarget.JVM_9)
137-
// To support LV override when set in aggregate builds
138-
languageVersion.set(compileTask.compilerOptions.languageVersion)
139149
freeCompilerArgs.addAll(
140150
listOf("-Xjdk-release=9", "-Xsuppress-version-warnings", "-Xexpect-actual-classes")
141151
)
142-
optIn.addAll(compileTask.kotlinOptions.options.optIn)
152+
optIn.addAll(compileTask.flatMap { it.compilerOptions.optIn })
143153
}
144154
// work-around for https://youtrack.jetbrains.com/issue/KT-60583
145155
inputs.files(
@@ -160,18 +170,21 @@ object Java9Modularity {
160170
.declaredMemberProperties
161171
.find { it.name == "ownModuleName" }
162172
?.get(this) as? Property<String>
163-
ownModuleNameProp?.set(compileTask.kotlinOptions.moduleName)
173+
ownModuleNameProp?.set(compileTask.flatMap { it.compilerOptions.moduleName})
164174
}
165175

166176
val taskKotlinLanguageVersion = compilerOptions.languageVersion.orElse(KotlinVersion.DEFAULT)
167177
@OptIn(InternalKotlinGradlePluginApi::class)
168178
if (taskKotlinLanguageVersion.get() < KotlinVersion.KOTLIN_2_0) {
169179
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
170180
@Suppress("INVISIBLE_MEMBER")
171-
commonSourceSet.from(compileTask.commonSourceSet)
181+
commonSourceSet.from(compileTask.map {
182+
@Suppress("INVISIBLE_MEMBER")
183+
it.commonSourceSet
184+
})
172185
} else {
173-
multiplatformStructure.refinesEdges.set(compileTask.multiplatformStructure.refinesEdges)
174-
multiplatformStructure.fragments.set(compileTask.multiplatformStructure.fragments)
186+
multiplatformStructure.refinesEdges.set(compileTask.flatMap { it.multiplatformStructure.refinesEdges })
187+
multiplatformStructure.fragments.set(compileTask.flatMap { it.multiplatformStructure.fragments })
175188
}
176189
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
177190
// and work-around for https://youtrack.jetbrains.com/issue/KT-60582
@@ -181,7 +194,7 @@ object Java9Modularity {
181194
}
182195

183196
private fun Project.registerCompileModuleTask(
184-
compileTask: KotlinCompile,
197+
compileTask: TaskProvider<KotlinCompile>,
185198
sourceFile: File,
186199
targetDirectory: Provider<out Directory>
187200
) = tasks.register("${compileTask.name}Module", JavaCompile::class) {
@@ -201,10 +214,12 @@ object Java9Modularity {
201214

202215
options.compilerArgumentProviders.add(object : CommandLineArgumentProvider {
203216
@get:CompileClasspath
204-
val compileClasspath = compileTask.libraries
217+
val compileClasspath = objects.fileCollection().from(
218+
compileTask.map { it.libraries }
219+
)
205220

206221
@get:CompileClasspath
207-
val compiledClasses = compileTask.destinationDirectory
222+
val compiledClasses = compileTask.flatMap { it.destinationDirectory }
208223

209224
@get:Input
210225
val moduleName = sourceFile

buildSrc/src/main/kotlin/dokka-conventions.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import org.jetbrains.dokka.gradle.*
6-
import java.net.URL
6+
import java.net.URI
77

88
/*
99
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
@@ -71,7 +71,7 @@ tasks.withType<DokkaTaskPartial>().named("dokkaHtmlPartial") {
7171
sourceLink {
7272
localDirectory.set(rootDir)
7373

74-
remoteUrl.set(URL("https://github.com/Kotlin/kotlinx.serialization/tree/master"))
74+
remoteUrl.set(URI("https://github.com/Kotlin/kotlinx.serialization/tree/master").toURL())
7575
remoteLineSuffix.set("#L")
7676
}
7777
}

buildSrc/src/main/kotlin/native-targets-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ kotlin {
4545
watchosDeviceArm64()
4646

4747
// Deprecated, but not removed
48+
@Suppress("DEPRECATION")
4849
linuxArm32Hfp()
4950
}
5051

buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
@file:OptIn(ExperimentalWasmDsl::class)
6-
75
import org.gradle.kotlin.dsl.*
86
import org.jetbrains.kotlin.gradle.plugin.mpp.*
97
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
10-
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
118
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
129
import org.jetbrains.kotlin.gradle.testing.*
10+
import org.jetbrains.kotlin.gradle.*
11+
import org.jetbrains.kotlin.gradle.dsl.*
12+
import org.jetbrains.kotlin.gradle.plugin.mpp.*
13+
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
14+
import org.jetbrains.kotlin.gradle.tasks.*
15+
import org.jetbrains.kotlin.gradle.testing.*
16+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
1317

1418
plugins {
1519
kotlin("multiplatform")
@@ -34,11 +38,14 @@ kotlin {
3438
explicitApi()
3539

3640
jvm {
41+
@Suppress("DEPRECATION") // Migrate on Kotlin 2.1.20 update
3742
withJava()
3843
compilations.configureEach {
39-
kotlinOptions {
40-
jvmTarget = "1.8"
41-
freeCompilerArgs += "-Xjdk-release=1.8"
44+
compileTaskProvider.configure {
45+
compilerOptions {
46+
jvmTarget = JvmTarget.JVM_1_8
47+
freeCompilerArgs.add("-Xjdk-release=1.8")
48+
}
4249
}
4350
}
4451
}
@@ -52,18 +59,22 @@ kotlin {
5259
}
5360
}
5461
compilations.matching { it.name == "main" || it.name == "test" }.configureEach {
55-
kotlinOptions {
56-
sourceMap = true
57-
moduleKind = "umd"
62+
compileTaskProvider.configure {
63+
compilerOptions {
64+
sourceMap = true
65+
moduleName = "umd"
66+
}
5867
}
5968
}
6069
}
6170

71+
@OptIn(ExperimentalWasmDsl::class)
6272
wasmJs {
6373
nodejs()
6474
}
6575

6676
if (!isOkIoOrFormatTests) {
77+
@OptIn(ExperimentalWasmDsl::class)
6778
wasmWasi {
6879
nodejs()
6980
}
@@ -164,18 +175,18 @@ kotlin {
164175
}
165176
}
166177

167-
targets.all {
168-
compilations.all {
169-
kotlinOptions {
170-
if (overriddenLanguageVersion != null) {
171-
languageVersion = overriddenLanguageVersion
172-
freeCompilerArgs += "-Xsuppress-version-warnings"
173-
}
174-
freeCompilerArgs += "-Xexpect-actual-classes"
175-
}
178+
compilerOptions {
179+
if (overriddenLanguageVersion != null) {
180+
languageVersion = KotlinVersion.fromVersion(overriddenLanguageVersion!!)
181+
freeCompilerArgs.add("-Xsuppress-version-warnings")
176182
}
177-
compilations["main"].kotlinOptions {
178-
allWarningsAsErrors = true
183+
freeCompilerArgs.add("-Xexpect-actual-classes")
184+
}
185+
186+
187+
targets.all {
188+
compilations["main"].compileTaskProvider.configure {
189+
compilerOptions.allWarningsAsErrors = true
179190
}
180191
}
181192
}

buildSrc/src/main/kotlin/teamcity-conventions.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
import org.gradle.kotlin.dsl.*
6-
75
val teamcitySuffix = findProperty("teamcitySuffix")?.toString()
86
if (teamcityInteractionEnabled && hasProperty("teamcity") && !propertyIsTrue("build_snapshot_train")) {
97
// Tell teamcity about version number
108
val postfix = if (teamcitySuffix == null) "" else " ($teamcitySuffix)"
119
println("##teamcity[buildNumber '${project.version}${postfix}']")
1210

13-
gradle.taskGraph.beforeTask {
14-
println("##teamcity[progressMessage 'Gradle: ${path}:${name}']")
11+
tasks.configureEach {
12+
doFirst {
13+
println("##teamcity[progressMessage 'Gradle: ${path}:${name}']")
14+
}
1515
}
1616
}

0 commit comments

Comments
 (0)