Skip to content

Commit 1407535

Browse files
authored
Fix deprecation warnings and enable warningsAsErrors for buildSrc (#4464)
K/JS related deprecation warnings are to be promoted to error within KT-68597 in Kotlin 2.2
1 parent 52c4755 commit 1407535

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

buildSrc/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ fun version(target: String): String {
3838
return properties[version]?.let{"$it"} ?: gradleProperties.getProperty(version)
3939
}
4040

41+
kotlin {
42+
compilerOptions {
43+
allWarningsAsErrors = true
44+
}
45+
}
46+
4147
dependencies {
4248
implementation(kotlin("gradle-plugin", version("kotlin")))
4349
/*

buildSrc/src/main/kotlin/AuxBuildConfiguration.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import CacheRedirector.configure
2-
import org.gradle.api.Project
3-
import org.gradle.api.tasks.*
1+
import org.gradle.api.*
42
import org.gradle.kotlin.dsl.*
53

64
/**
@@ -17,7 +15,7 @@ object AuxBuildConfiguration {
1715
workaroundForCoroutinesLeakageToClassPath()
1816
}
1917

20-
CacheRedirector.configureJsPackageManagers(rootProject)
18+
CacheRedirector.configureRootJsPackageManagers(rootProject)
2119

2220
// Sigh, there is no BuildScanExtension in classpath when there is no --scan
2321
rootProject.extensions.findByName("buildScan")?.withGroovyBuilder {

buildSrc/src/main/kotlin/CacheRedirector.kt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
12
import org.gradle.api.*
23
import org.gradle.api.artifacts.dsl.*
34
import org.gradle.api.artifacts.repositories.*
45
import org.gradle.api.initialization.dsl.*
56
import org.gradle.kotlin.dsl.*
67
import org.jetbrains.kotlin.gradle.targets.js.nodejs.*
7-
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.*
88
import org.jetbrains.kotlin.gradle.targets.js.yarn.*
99
import java.net.*
1010

@@ -100,16 +100,28 @@ private fun Project.checkRedirect(repositories: RepositoryHandler, containerName
100100
}
101101
}
102102

103-
private fun Project.configureYarnAndNodeRedirects() {
103+
private fun Project.configureYarnRedirects() {
104104
if (CacheRedirector.isEnabled) {
105-
val yarnRootExtension = extensions.findByType<YarnRootExtension>()
106-
yarnRootExtension?.downloadBaseUrl?.let {
107-
yarnRootExtension.downloadBaseUrl = CacheRedirector.maybeRedirect(it)
105+
plugins.withType(YarnPlugin::class) {
106+
extensions.configure(YarnRootEnvSpec::class.java) {
107+
// no API to modify the value in-place keeping it lazy: https://github.com/gradle/gradle/issues/27227
108+
downloadBaseUrl.orNull?.let {
109+
downloadBaseUrl = CacheRedirector.maybeRedirect(it)
110+
}
111+
}
108112
}
113+
}
114+
}
109115

110-
val nodeJsExtension = rootProject.extensions.findByType<NodeJsRootExtension>()
111-
nodeJsExtension?.downloadBaseUrl?.let {
112-
nodeJsExtension.downloadBaseUrl = CacheRedirector.maybeRedirect(it)
116+
private fun Project.configureNodeJsRedirects() {
117+
if (CacheRedirector.isEnabled) {
118+
plugins.withType(NodeJsPlugin::class) {
119+
extensions.configure(NodeJsEnvSpec::class.java) {
120+
// no API to modify the value in-place keeping it lazy: https://github.com/gradle/gradle/issues/27227
121+
downloadBaseUrl.orNull?.let {
122+
downloadBaseUrl = CacheRedirector.maybeRedirect(it)
123+
}
124+
}
113125
}
114126
}
115127
}
@@ -128,14 +140,16 @@ object CacheRedirector {
128140
@JvmStatic
129141
fun configure(project: Project) {
130142
project.checkRedirect(project.repositories, project.displayName)
143+
project.configureNodeJsRedirects()
131144
}
132145

133146
/**
134-
* Configures JS-specific extensions to use
147+
* Configures JS-specific extensions defined on the root project to use cache redirector
148+
* For example, KGP provides Yarn configuration only globally for the entire build via the root project.
135149
*/
136150
@JvmStatic
137-
fun configureJsPackageManagers(project: Project) {
138-
project.configureYarnAndNodeRedirects()
151+
fun configureRootJsPackageManagers(rootProject: Project) {
152+
rootProject.configureYarnRedirects()
139153
}
140154

141155
@JvmStatic

buildSrc/src/main/kotlin/CommunityProjectsBuild.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import org.gradle.api.*
44
import org.gradle.api.artifacts.dsl.*
5-
import org.gradle.api.tasks.testing.Test
5+
import org.gradle.api.tasks.testing.*
66
import org.gradle.kotlin.dsl.*
7-
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
7+
import org.jetbrains.kotlin.gradle.dsl.*
88
import java.net.*
99
import java.util.logging.*
10-
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
1110

1211
private val LOGGER: Logger = Logger.getLogger("Kotlin settings logger")
1312

@@ -107,7 +106,7 @@ fun Project.configureCommunityBuildTweaks() {
107106
val coreProject = subprojects.single { it.name == coreModule }
108107
configure(listOf(coreProject)) {
109108
configurations.matching { it.name == "kotlinCompilerClasspath" }.configureEach {
110-
val config = resolvedConfiguration.files.single { it.name.contains("kotlin-compiler-embeddable") }
109+
val config = incoming.files.single { it.name.contains("kotlin-compiler-embeddable") }
111110

112111
val manifest = zipTree(config).matching {
113112
include("META-INF/MANIFEST.MF")

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.gradle.api.*
21
import org.gradle.api.tasks.testing.logging.*
32
import org.jetbrains.kotlin.gradle.dsl.*
43

@@ -47,7 +46,7 @@ kotlin {
4746
watchosDeviceArm64()
4847
}
4948
js {
50-
moduleName = project.name
49+
outputModuleName = project.name
5150
nodejs()
5251
compilations["main"]?.dependencies {
5352
api("org.jetbrains.kotlinx:atomicfu-js:${version("atomicfu")}")
@@ -57,7 +56,7 @@ kotlin {
5756
wasmJs {
5857
// Module name should be different from the one from JS
5958
// otherwise IC tasks that start clashing different modules with the same module name
60-
moduleName = project.name + "Wasm"
59+
outputModuleName = project.name + "Wasm"
6160
nodejs()
6261
compilations["main"]?.dependencies {
6362
api("org.jetbrains.kotlinx:atomicfu-wasm-js:${version("atomicfu")}")

0 commit comments

Comments
 (0)