Skip to content

Commit aa5f75b

Browse files
authored
Merge pull request #35 from skydoves/issue/gradle-9.x
Uses lazy configuration to avoid eager task resolution and Gradle 9.x compatibility issues
2 parents a6f3120 + 3fb536f commit aa5f75b

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

stability-gradle/src/main/kotlin/com/skydoves/compose/stability/gradle/StabilityAnalyzerGradlePlugin.kt

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
8989
ignoredClasses.set(extension.stabilityValidation.ignoredClasses)
9090
}
9191

92-
// Make check task depend on stabilityCheck if enabled
93-
target.tasks.named("check") {
94-
dependsOn(stabilityCheckTask)
92+
// Make check task depend on stabilityCheck if enabled (only if check task exists)
93+
target.plugins.withId("base") {
94+
target.tasks.named("check") {
95+
dependsOn(stabilityCheckTask)
96+
}
9597
}
9698

9799
// Configure after project evaluation
@@ -211,28 +213,54 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
211213

212214
/**
213215
* Configure task dependencies for stability dump and check tasks.
216+
* Uses lazy configuration to avoid eager task resolution and Gradle 9.x compatibility issues.
214217
*/
215218
private fun configureTaskDependencies(
216219
project: Project,
217220
extension: StabilityAnalyzerExtension,
218221
stabilityDumpTask: org.gradle.api.tasks.TaskProvider<StabilityDumpTask>,
219222
stabilityCheckTask: org.gradle.api.tasks.TaskProvider<StabilityCheckTask>,
220223
) {
221-
val includeTests = extension.stabilityValidation.includeTests.get()
222-
223-
project.tasks.matching { task ->
224-
val isKotlinCompile = task.name.startsWith("compile") && task.name.contains("Kotlin")
225-
val isTestTask = task.name.lowercase().let {
226-
it.contains("test") || it.contains("androidtest") || it.contains("unittest")
227-
}
224+
// Get the includeTests provider for lazy evaluation
225+
val includeTestsProvider = extension.stabilityValidation.includeTests
226+
227+
// Configure dependencies lazily using TaskProvider
228+
stabilityDumpTask.configure {
229+
// Use provider to lazily collect Kotlin compile task names
230+
dependsOn(
231+
project.provider {
232+
val includeTests = includeTestsProvider.get()
233+
project.tasks.matching { task ->
234+
val isKotlinCompile = task.name.startsWith("compile") && task.name.contains("Kotlin")
235+
val isTestTask = task.name.lowercase().let {
236+
it.contains("test") || it.contains("androidtest") || it.contains("unittest")
237+
}
238+
// Include task if it's a Kotlin compile task and either:
239+
// 1. includeTests is true, OR
240+
// 2. it's not a test task
241+
isKotlinCompile && (includeTests || !isTestTask)
242+
}
243+
},
244+
)
245+
}
228246

229-
// Include task if it's a Kotlin compile task and either:
230-
// 1. includeTests is true, OR
231-
// 2. it's not a test task
232-
isKotlinCompile && (includeTests || !isTestTask)
233-
}.all {
234-
stabilityDumpTask.get().dependsOn(this)
235-
stabilityCheckTask.get().dependsOn(this)
247+
stabilityCheckTask.configure {
248+
// Use provider to lazily collect Kotlin compile task names
249+
dependsOn(
250+
project.provider {
251+
val includeTests = includeTestsProvider.get()
252+
project.tasks.matching { task ->
253+
val isKotlinCompile = task.name.startsWith("compile") && task.name.contains("Kotlin")
254+
val isTestTask = task.name.lowercase().let {
255+
it.contains("test") || it.contains("androidtest") || it.contains("unittest")
256+
}
257+
// Include task if it's a Kotlin compile task and either:
258+
// 1. includeTests is true, OR
259+
// 2. it's not a test task
260+
isKotlinCompile && (includeTests || !isTestTask)
261+
}
262+
},
263+
)
236264
}
237265
}
238266

0 commit comments

Comments
 (0)