Skip to content

Commit 73e7067

Browse files
authored
Merge pull request #56 from skydoves/plugin/failOnStabilityChange
Implement failOnStabilityChange property for the gradle plugin
2 parents ab353bc + 385119f commit 73e7067

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

stability-gradle/api/stability-gradle.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class com/skydoves/compose/stability/gradle/StabilityAnalyzerGradle
2323
public abstract class com/skydoves/compose/stability/gradle/StabilityCheckTask : org/gradle/api/DefaultTask {
2424
public fun <init> ()V
2525
public final fun check ()V
26+
public abstract fun getFailOnStabilityChange ()Lorg/gradle/api/provider/Property;
2627
public abstract fun getIgnoredClasses ()Lorg/gradle/api/provider/ListProperty;
2728
public abstract fun getIgnoredPackages ()Lorg/gradle/api/provider/ListProperty;
2829
public abstract fun getProjectName ()Lorg/gradle/api/provider/Property;
@@ -43,6 +44,7 @@ public abstract class com/skydoves/compose/stability/gradle/StabilityDumpTask :
4344
public abstract class com/skydoves/compose/stability/gradle/StabilityValidationConfig {
4445
public fun <init> (Lorg/gradle/api/file/ProjectLayout;Lorg/gradle/api/model/ObjectFactory;)V
4546
public final fun getEnabled ()Lorg/gradle/api/provider/Property;
47+
public final fun getFailOnStabilityChange ()Lorg/gradle/api/provider/Property;
4648
public final fun getIgnoredClasses ()Lorg/gradle/api/provider/ListProperty;
4749
public final fun getIgnoredPackages ()Lorg/gradle/api/provider/ListProperty;
4850
public final fun getIgnoredProjects ()Lorg/gradle/api/provider/ListProperty;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,12 @@ public abstract class StabilityValidationConfig @Inject constructor(
132132
*/
133133
public val ignoredClasses: ListProperty<String> =
134134
objects.listProperty(String::class.java).convention(emptyList())
135+
136+
/**
137+
* Whether to fail the build when stability changes are detected.
138+
* When false, stability changes will be logged as warnings instead.
139+
* Default: true
140+
*/
141+
public val failOnStabilityChange: Property<Boolean> =
142+
objects.property(Boolean::class.javaObjectType).convention(true)
135143
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
8989
stabilityDir.set(extension.stabilityValidation.outputDir)
9090
ignoredPackages.set(extension.stabilityValidation.ignoredPackages)
9191
ignoredClasses.set(extension.stabilityValidation.ignoredClasses)
92+
failOnStabilityChange.set(extension.stabilityValidation.failOnStabilityChange)
9293
}
9394

9495
// Make check task depend on stabilityCheck if enabled (only if check task exists)

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public abstract class StabilityCheckTask : DefaultTask() {
6262
@get:Input
6363
public abstract val projectName: Property<String>
6464

65+
/**
66+
* Whether to fail the build when stability changes are detected.
67+
*/
68+
@get:Input
69+
public abstract val failOnStabilityChange: Property<Boolean>
70+
6571
init {
6672
group = "verification"
6773
description = "Check composable stability against reference file"
@@ -110,8 +116,6 @@ public abstract class StabilityCheckTask : DefaultTask() {
110116

111117
if (differences.isNotEmpty()) {
112118
val message = buildString {
113-
appendLine("❌ Stability check failed!")
114-
appendLine()
115119
appendLine("The following composables have changed stability:")
116120
appendLine()
117121
differences.forEach { diff ->
@@ -123,10 +127,16 @@ public abstract class StabilityCheckTask : DefaultTask() {
123127
"to update the stability file.",
124128
)
125129
}
126-
throw GradleException(message)
127-
}
128130

129-
logger.lifecycle("✅ Stability check passed.")
131+
if (failOnStabilityChange.get()) {
132+
throw GradleException("❌ Stability check failed!\n\n$message")
133+
} else {
134+
logger.warn("⚠️ Stability changes detected:\n\n$message")
135+
logger.lifecycle("✓ Stability check completed with warnings (failOnStabilityChange=false)")
136+
}
137+
} else {
138+
logger.lifecycle("✅ Stability check passed.")
139+
}
130140
}
131141

132142
private fun parseStabilityFromCompiler(

0 commit comments

Comments
 (0)