Skip to content

Commit e50b0e7

Browse files
Tapchicomawoainikk
authored andcommitted
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 cf0c152 commit e50b0e7

15 files changed

+137
-133
lines changed

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: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import kotlin.reflect.*
2727
import kotlin.reflect.full.*
2828

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

3138
@JvmStatic
3239
@JvmOverloads
@@ -49,16 +56,19 @@ object Java9Modularity {
4956
}
5057

5158
target.compilations.forEach { compilation ->
52-
val compileKotlinTask = compilation.compileKotlinTask as KotlinCompile
59+
@Suppress("UNCHECKED_CAST")
60+
val compileKotlinTask = compilation.compileTaskProvider as TaskProvider<KotlinCompile>
5361
val defaultSourceSet = compilation.defaultSourceSet
5462

5563
// derive the names of the source set and compile module task
5664
val sourceSetName = defaultSourceSet.name + "Module"
5765

5866
kotlin.sourceSets.create(sourceSetName) {
5967
val sourceFile = this.kotlin.find { it.name == "module-info.java" }
60-
val targetDirectory = compileKotlinTask.destinationDirectory.map {
61-
it.dir("../${it.asFile.name}Module")
68+
val targetDirectory = compileKotlinTask.flatMap { task ->
69+
task.destinationDirectory.map {
70+
it.dir("../${it.asFile.name}Module")
71+
}
6272
}
6373

6474
// only configure the compilation if necessary
@@ -109,37 +119,38 @@ object Java9Modularity {
109119
* but it currently won't compile to a module-info.class file.
110120
*/
111121
private fun Project.registerVerifyModuleTask(
112-
compileTask: KotlinCompile,
122+
compileTask: TaskProvider<KotlinCompile>,
113123
sourceFile: File
114124
): TaskProvider<out KotlinJvmCompile> {
115125
apply<KotlinApiPlugin>()
126+
@Suppress("DEPRECATION")
116127
val verifyModuleTaskName = "verify${compileTask.name.removePrefix("compile").capitalize()}Module"
117128
// work-around for https://youtrack.jetbrains.com/issue/KT-60542
118129
val kotlinApiPlugin = plugins.getPlugin(KotlinApiPlugin::class)
119130
val verifyModuleTask = kotlinApiPlugin.registerKotlinJvmCompileTask(
120131
verifyModuleTaskName,
121-
compileTask.compilerOptions.moduleName.get()
132+
compilerOptions = compileTask.get().compilerOptions,
133+
explicitApiMode = provider { ExplicitApiMode.Disabled }
122134
)
123135
verifyModuleTask {
124136
group = VERIFICATION_GROUP
125137
description = "Verify Kotlin sources for JPMS problems"
126-
libraries.from(compileTask.libraries)
127-
source(compileTask.sources)
128-
source(compileTask.javaSources)
138+
libraries.from(compileTask.map { it.libraries })
139+
source(compileTask.map { it.sources })
140+
source(compileTask.map { it.javaSources })
129141
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
130-
@Suppress("INVISIBLE_MEMBER")
131-
source(compileTask.scriptSources)
142+
source(compileTask.map {
143+
@Suppress("INVISIBLE_MEMBER")
144+
it.scriptSources
145+
})
132146
source(sourceFile)
133147
destinationDirectory.set(temporaryDir)
134-
multiPlatformEnabled.set(compileTask.multiPlatformEnabled)
148+
multiPlatformEnabled.set(compileTask.get().multiPlatformEnabled)
135149
compilerOptions {
136150
jvmTarget.set(JvmTarget.JVM_9)
137-
// To support LV override when set in aggregate builds
138-
languageVersion.set(compileTask.compilerOptions.languageVersion)
139151
freeCompilerArgs.addAll(
140152
listOf("-Xjdk-release=9", "-Xsuppress-version-warnings", "-Xexpect-actual-classes")
141153
)
142-
optIn.addAll(compileTask.kotlinOptions.options.optIn)
143154
}
144155
// work-around for https://youtrack.jetbrains.com/issue/KT-60583
145156
inputs.files(
@@ -160,18 +171,21 @@ object Java9Modularity {
160171
.declaredMemberProperties
161172
.find { it.name == "ownModuleName" }
162173
?.get(this) as? Property<String>
163-
ownModuleNameProp?.set(compileTask.kotlinOptions.moduleName)
174+
ownModuleNameProp?.set(compileTask.flatMap { it.compilerOptions.moduleName})
164175
}
165176

166177
val taskKotlinLanguageVersion = compilerOptions.languageVersion.orElse(KotlinVersion.DEFAULT)
167178
@OptIn(InternalKotlinGradlePluginApi::class)
168179
if (taskKotlinLanguageVersion.get() < KotlinVersion.KOTLIN_2_0) {
169180
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
170181
@Suppress("INVISIBLE_MEMBER")
171-
commonSourceSet.from(compileTask.commonSourceSet)
182+
commonSourceSet.from(compileTask.map {
183+
@Suppress("INVISIBLE_MEMBER")
184+
it.commonSourceSet
185+
})
172186
} else {
173-
multiplatformStructure.refinesEdges.set(compileTask.multiplatformStructure.refinesEdges)
174-
multiplatformStructure.fragments.set(compileTask.multiplatformStructure.fragments)
187+
multiplatformStructure.refinesEdges.set(compileTask.flatMap { it.multiplatformStructure.refinesEdges })
188+
multiplatformStructure.fragments.set(compileTask.flatMap { it.multiplatformStructure.fragments })
175189
}
176190
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
177191
// and work-around for https://youtrack.jetbrains.com/issue/KT-60582
@@ -181,7 +195,7 @@ object Java9Modularity {
181195
}
182196

183197
private fun Project.registerCompileModuleTask(
184-
compileTask: KotlinCompile,
198+
compileTask: TaskProvider<KotlinCompile>,
185199
sourceFile: File,
186200
targetDirectory: Provider<out Directory>
187201
) = tasks.register("${compileTask.name}Module", JavaCompile::class) {
@@ -201,10 +215,12 @@ object Java9Modularity {
201215

202216
options.compilerArgumentProviders.add(object : CommandLineArgumentProvider {
203217
@get:CompileClasspath
204-
val compileClasspath = compileTask.libraries
218+
val compileClasspath = objects.fileCollection().from(
219+
compileTask.map { it.libraries }
220+
)
205221

206222
@get:CompileClasspath
207-
val compiledClasses = compileTask.destinationDirectory
223+
val compiledClasses = compileTask.flatMap { it.destinationDirectory }
208224

209225
@get:Input
210226
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

0 commit comments

Comments
 (0)