Skip to content

Commit 1e2e9fc

Browse files
committed
Fix lints in KspConfigurations
1 parent 383cb69 commit 1e2e9fc

File tree

2 files changed

+17
-37
lines changed

2 files changed

+17
-37
lines changed

gradle-plugin/lint-baseline.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<issues format="6" by="lint 8.13.0" type="baseline" client="gradle" dependencies="false" name="AGP (8.13.0)" variant="all" version="8.13.0">
33

4-
<issue
5-
id="EagerGradleConfiguration"
6-
message="Use register instead of create"
7-
errorLine1=" private val configurationForAll = project.configurations.create(PREFIX).apply {"
8-
errorLine2=" ~~~~~~">
9-
<location
10-
file="src/main/kotlin/com/google/devtools/ksp/gradle/KspConfigurations.kt"
11-
line="28"
12-
column="62"/>
13-
</issue>
14-
154
<issue
165
id="EagerGradleConfiguration"
176
message="Use register instead of maybeCreate"
@@ -23,17 +12,6 @@
2312
column="39"/>
2413
</issue>
2514

26-
<issue
27-
id="EagerGradleConfiguration"
28-
message="Use configureEach instead of whenObjectAdded"
29-
errorLine1=" configurationForAll.dependencies.whenObjectAdded {"
30-
errorLine2=" ~~~~~~~~~~~~~~~">
31-
<location
32-
file="src/main/kotlin/com/google/devtools/ksp/gradle/KspConfigurations.kt"
33-
line="122"
34-
column="50"/>
35-
</issue>
36-
3715
<issue
3816
id="EagerGradleConfiguration"
3917
message="Use register instead of maybeCreate"

gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspConfigurations.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class KspConfigurations(private val project: Project) {
2525
?: true
2626

2727
// The "ksp" configuration, applied to every compilation.
28-
private val configurationForAll = project.configurations.create(PREFIX).apply {
29-
isCanBeConsumed = false
30-
isCanBeResolved = false
31-
isVisible = false
28+
private val configurationForAll = project.configurations.register(PREFIX) {
29+
it.isCanBeConsumed = false
30+
it.isCanBeResolved = false
31+
it.isVisible = false
3232
}
3333

3434
private fun configurationNameOf(vararg parts: String): String {
@@ -118,17 +118,19 @@ class KspConfigurations(private val project: Project) {
118118
is KotlinMultiplatformExtension -> {
119119
kotlin.targets.configureEach { decorateKotlinTarget(it, isKotlinMultiplatform = true) }
120120

121-
var reported = false
122-
configurationForAll.dependencies.whenObjectAdded {
123-
if (!reported) {
124-
reported = true
125-
val msg = "The 'ksp' configuration is deprecated in Kotlin Multiplatform projects. " +
126-
"Please use target-specific configurations like 'kspJvm' instead."
127-
128-
if (allowAllTargetConfiguration) {
129-
project.logger.warn(msg)
130-
} else {
131-
throw InvalidUserCodeException(msg)
121+
configurationForAll.configure { configuration ->
122+
var reported = false
123+
configuration.dependencies.configureEach {
124+
if (!reported) {
125+
reported = true
126+
val msg = "The 'ksp' configuration is deprecated in Kotlin Multiplatform projects. " +
127+
"Please use target-specific configurations like 'kspJvm' instead."
128+
129+
if (allowAllTargetConfiguration) {
130+
project.logger.warn(msg)
131+
} else {
132+
throw InvalidUserCodeException(msg)
133+
}
132134
}
133135
}
134136
}

0 commit comments

Comments
 (0)