Skip to content

Commit 5439653

Browse files
authored
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.
1 parent 87bb0ea commit 5439653

15 files changed

+90
-56
lines changed

bom/build.gradle.kts

+5-2
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

+3-4
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
@@ -159,10 +160,8 @@ tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstall
159160
args.add("--ignore-engines")
160161
}
161162

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

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

buildSrc/build.gradle.kts

+6
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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.kotlin.dsl.allWarningsAsErrors=true

buildSrc/src/main/kotlin/Java9Modularity.kt

+36-23
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@ 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
2322
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
24-
import org.jetbrains.kotlin.gradle.utils.*
2523
import org.jetbrains.kotlin.tooling.core.*
2624
import java.io.*
2725
import kotlin.reflect.*
2826
import kotlin.reflect.full.*
2927

3028
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+
3136

3237
@JvmStatic
3338
@JvmOverloads
@@ -50,16 +55,19 @@ object Java9Modularity {
5055
}
5156

5257
target.compilations.forEach { compilation ->
53-
val compileKotlinTask = compilation.compileKotlinTask as KotlinCompile
58+
@Suppress("UNCHECKED_CAST")
59+
val compileKotlinTask = compilation.compileTaskProvider as TaskProvider<KotlinCompile>
5460
val defaultSourceSet = compilation.defaultSourceSet
5561

5662
// derive the names of the source set and compile module task
5763
val sourceSetName = defaultSourceSet.name + "Module"
5864

5965
kotlin.sourceSets.create(sourceSetName) {
6066
val sourceFile = this.kotlin.find { it.name == "module-info.java" }
61-
val targetDirectory = compileKotlinTask.destinationDirectory.map {
62-
it.dir("../${it.asFile.name}Module")
67+
val targetDirectory = compileKotlinTask.flatMap { task ->
68+
task.destinationDirectory.map {
69+
it.dir("../${it.asFile.name}Module")
70+
}
6371
}
6472

6573
// only configure the compilation if necessary
@@ -110,7 +118,7 @@ object Java9Modularity {
110118
* but it currently won't compile to a module-info.class file.
111119
*/
112120
private fun Project.registerVerifyModuleTask(
113-
compileTask: KotlinCompile,
121+
compileTask: TaskProvider<KotlinCompile>,
114122
sourceFile: File
115123
): TaskProvider<out KotlinJvmCompile> {
116124
apply<KotlinApiPlugin>()
@@ -120,28 +128,28 @@ object Java9Modularity {
120128
val kotlinApiPlugin = plugins.getPlugin(KotlinApiPlugin::class)
121129
val verifyModuleTask = kotlinApiPlugin.registerKotlinJvmCompileTask(
122130
verifyModuleTaskName,
123-
compileTask.compilerOptions.moduleName.get()
131+
compilerOptions = compileTask.get().compilerOptions,
132+
explicitApiMode = provider { ExplicitApiMode.Disabled }
124133
)
125134
verifyModuleTask {
126135
group = VERIFICATION_GROUP
127136
description = "Verify Kotlin sources for JPMS problems"
128-
libraries.from(compileTask.libraries)
129-
source(compileTask.sources)
130-
source(compileTask.javaSources)
137+
libraries.from(compileTask.map { it.libraries })
138+
source(compileTask.map { it.sources })
139+
source(compileTask.map { it.javaSources })
131140
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
132-
@Suppress("INVISIBLE_MEMBER")
133-
source(compileTask.scriptSources)
141+
source(compileTask.map {
142+
@Suppress("INVISIBLE_MEMBER")
143+
it.scriptSources
144+
})
134145
source(sourceFile)
135146
destinationDirectory.set(temporaryDir)
136-
multiPlatformEnabled.set(compileTask.multiPlatformEnabled)
147+
multiPlatformEnabled.set(compileTask.get().multiPlatformEnabled)
137148
compilerOptions {
138149
jvmTarget.set(JvmTarget.JVM_9)
139-
// To support LV override when set in aggregate builds
140-
languageVersion.set(compileTask.compilerOptions.languageVersion)
141150
freeCompilerArgs.addAll(
142151
listOf("-Xjdk-release=9", "-Xsuppress-version-warnings", "-Xexpect-actual-classes")
143152
)
144-
optIn.addAll(compileTask.compilerOptions.optIn)
145153
}
146154
// work-around for https://youtrack.jetbrains.com/issue/KT-60583
147155
inputs.files(
@@ -162,18 +170,21 @@ object Java9Modularity {
162170
.declaredMemberProperties
163171
.find { it.name == "ownModuleName" }
164172
?.get(this) as? Property<String>
165-
ownModuleNameProp?.set(compileTask.compilerOptions.moduleName)
173+
ownModuleNameProp?.set(compileTask.flatMap { it.compilerOptions.moduleName})
166174
}
167175

168176
val taskKotlinLanguageVersion = compilerOptions.languageVersion.orElse(KotlinVersion.DEFAULT)
169177
@OptIn(InternalKotlinGradlePluginApi::class)
170178
if (taskKotlinLanguageVersion.get() < KotlinVersion.KOTLIN_2_0) {
171179
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
172180
@Suppress("INVISIBLE_MEMBER")
173-
commonSourceSet.from(compileTask.commonSourceSet)
181+
commonSourceSet.from(compileTask.map {
182+
@Suppress("INVISIBLE_MEMBER")
183+
it.commonSourceSet
184+
})
174185
} else {
175-
multiplatformStructure.refinesEdges.set(compileTask.multiplatformStructure.refinesEdges)
176-
multiplatformStructure.fragments.set(compileTask.multiplatformStructure.fragments)
186+
multiplatformStructure.refinesEdges.set(compileTask.flatMap { it.multiplatformStructure.refinesEdges })
187+
multiplatformStructure.fragments.set(compileTask.flatMap { it.multiplatformStructure.fragments })
177188
}
178189
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
179190
// and work-around for https://youtrack.jetbrains.com/issue/KT-60582
@@ -183,7 +194,7 @@ object Java9Modularity {
183194
}
184195

185196
private fun Project.registerCompileModuleTask(
186-
compileTask: KotlinCompile,
197+
compileTask: TaskProvider<KotlinCompile>,
187198
sourceFile: File,
188199
targetDirectory: Provider<out Directory>
189200
) = tasks.register("${compileTask.name}Module", JavaCompile::class) {
@@ -203,10 +214,12 @@ object Java9Modularity {
203214

204215
options.compilerArgumentProviders.add(object : CommandLineArgumentProvider {
205216
@get:CompileClasspath
206-
val compileClasspath = compileTask.libraries
217+
val compileClasspath = objects.fileCollection().from(
218+
compileTask.map { it.libraries }
219+
)
207220

208221
@get:CompileClasspath
209-
val compiledClasses = compileTask.destinationDirectory
222+
val compiledClasses = compileTask.flatMap { it.destinationDirectory }
210223

211224
@get:Input
212225
val moduleName = sourceFile

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

+2-2
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

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ kotlin {
4545
androidNativeX64()
4646

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

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@
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.*
97
import org.jetbrains.kotlin.gradle.dsl.*
10-
import org.jetbrains.kotlin.gradle.plugin.mpp.*
11-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
12-
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
13-
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
148
import org.jetbrains.kotlin.gradle.tasks.*
15-
import org.jetbrains.kotlin.gradle.testing.*
169

1710
plugins {
1811
kotlin("multiplatform")
@@ -28,6 +21,7 @@ kotlin {
2821
explicitApi()
2922

3023
jvm {
24+
@Suppress("DEPRECATION") // Migrate on Kotlin 2.1.20 update
3125
withJava()
3226
@OptIn(ExperimentalKotlinGradlePluginApi::class)
3327
compilerOptions {
@@ -53,10 +47,12 @@ kotlin {
5347
}
5448
}
5549

50+
@OptIn(ExperimentalWasmDsl::class)
5651
wasmJs {
5752
nodejs()
5853
}
5954

55+
@OptIn(ExperimentalWasmDsl::class)
6056
wasmWasi {
6157
nodejs()
6258
}

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

+4-4
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
}

buildSrc/src/main/kotlin/utils.kt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.util.Locale
2+
3+
/*
4+
* Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
5+
*/
6+
7+
fun String.capitalizeCompat() = replaceFirstChar {
8+
if (it.isLowerCase()) it.titlecase(locale = Locale.getDefault()) else it.toString()
9+
}

formats/json-io/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tasks.named<DokkaTaskPartial>("dokkaHtmlPartial") {
3737
dokkaSourceSets {
3838
configureEach {
3939
externalDocumentationLink {
40-
url.set(URL("https://kotlin.github.io/kotlinx-io/"))
40+
url.set(URI("https://kotlin.github.io/kotlinx-io/").toURL())
4141
}
4242
}
4343
}

formats/json-okio/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tasks.named<DokkaTaskPartial>("dokkaHtmlPartial") {
3838
dokkaSourceSets {
3939
configureEach {
4040
externalDocumentationLink {
41-
url.set(URL("https://square.github.io/okio/3.x/okio/"))
41+
url.set(URI("https://square.github.io/okio/3.x/okio/").toURL())
4242
packageListUrl.set(
4343
file("dokka/okio.package.list").toURI().toURL()
4444
)

gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ kover.enabled=true
1515

1616
org.gradle.parallel=true
1717
org.gradle.caching=true
18+
org.gradle.kotlin.dsl.allWarningsAsErrors=true
1819

1920
#kotlin.native.jvmArgs=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5007
2021
#kotlin.native.disableCompilerDaemon=true

integration-test/build.gradle.kts

+15-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
55
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
66
import org.jetbrains.kotlin.gradle.plugin.mpp.*
7+
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
8+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
79

810
val serialization_version = property("mainLibVersion") as String
911

@@ -33,16 +35,16 @@ kotlin {
3335
// Switching module kind for JS is required to run tests
3436
js {
3537
nodejs {}
36-
compilations.matching { it.name == "main" || it.name == "test" }.configureEach {
37-
kotlinOptions {
38-
sourceMap = true
39-
moduleKind = "umd"
40-
}
38+
compilerOptions {
39+
sourceMap = true
40+
moduleKind = JsModuleKind.MODULE_UMD
4141
}
4242
}
43+
@OptIn(ExperimentalWasmDsl::class)
4344
wasmJs {
4445
nodejs()
4546
}
47+
@OptIn(ExperimentalWasmDsl::class)
4648
wasmWasi {
4749
nodejs()
4850
}
@@ -127,14 +129,16 @@ kotlin {
127129

128130
targets.all {
129131
compilations.all {
130-
kotlinOptions {
131-
freeCompilerArgs += "-Xexpect-actual-classes"
132+
compileTaskProvider.configure {
133+
compilerOptions.freeCompilerArgs.add("-Xexpect-actual-classes")
132134
}
133135
}
134-
compilations["main"].kotlinOptions {
135-
allWarningsAsErrors = true
136-
// Suppress 'K2 kapt is an experimental feature' warning:
137-
freeCompilerArgs += "-Xsuppress-version-warnings"
136+
compilations["main"].compileTaskProvider.configure {
137+
compilerOptions {
138+
allWarningsAsErrors = true
139+
// Suppress 'K2 kapt is an experimental feature' warning:
140+
freeCompilerArgs.add("-Xsuppress-version-warnings")
141+
}
138142
}
139143
}
140144

integration-test/gradle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mainKotlinVersion=2.1.0
66
mainLibVersion=1.8.0-SNAPSHOT
77

88
kotlin.code.style=official
9-
kotlin.js.compiler=ir
109

1110
gradle_node_version = 1.2.0
1211
node_version = 8.9.3
@@ -17,6 +16,8 @@ source_map_support_version = 0.5.3
1716

1817
kapt.use.k2=true
1918

19+
org.gradle.kotlin.dsl.allWarningsAsErrors=true
20+
2021
# Uncommend & insert path to local Native distribution if you want to test with SNAPSHOT compiler
2122
#kotlin.native.home=
2223

0 commit comments

Comments
 (0)