Skip to content

Commit b61d18a

Browse files
committed
Store stability output of Android variants to their own folder
1 parent 87fcf75 commit b61d18a

1 file changed

Lines changed: 41 additions & 10 deletions

File tree

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
7272
} else {
7373
registerTasksAndroid(target, extension, androidComponents)
7474
}
75-
76-
// Add output parameter to the Kotlin tasks to ensure it is compatible with the Build Cache
77-
target.tasks.withType(KotlinCompile::class.java).configureEach {
78-
val stabilityDir = target.layout.buildDirectory.dir("stability").get()
79-
outputs.dir(stabilityDir).optional(true)
80-
}
8175
}
8276

8377
private fun registerTasksNonAndroid(
@@ -131,6 +125,14 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
131125
configureTaskDependencies(target, extension, null, stabilityDumpTask, stabilityCheckTask)
132126
addRuntimeDependency(target)
133127
}
128+
129+
// Add output parameter to the Kotlin tasks to ensure it is compatible with the Build Cache
130+
target.tasks.withType(KotlinCompile::class.java)
131+
.named { isKotlinTaskApplicable(it, false) }
132+
.configureEach {
133+
val stabilityDir = target.layout.buildDirectory.dir("stability").get()
134+
outputs.dir(stabilityDir).optional(true)
135+
}
134136
}
135137

136138
private fun registerTasksAndroid(
@@ -158,7 +160,7 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
158160
) {
159161
projectName.set(target.name)
160162
stabilityInputFiles.setFrom(
161-
target.layout.buildDirectory.file("stability/stability-info.json"),
163+
target.layout.buildDirectory.file("stability/${variant.name}/stability-info.json"),
162164
)
163165
outputDir.set(extension.stabilityValidation.outputDir)
164166
ignoredPackages.set(extension.stabilityValidation.ignoredPackages)
@@ -175,7 +177,7 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
175177
) {
176178
projectName.set(target.name)
177179
stabilityInputFiles.from(
178-
target.layout.buildDirectory.file("stability/stability-info.json"),
180+
target.layout.buildDirectory.file("stability/${variant.name}/stability-info.json"),
179181
)
180182
stabilityReferenceFiles.from(extension.stabilityValidation.outputDir)
181183
ignoredPackages.set(extension.stabilityValidation.ignoredPackages)
@@ -212,6 +214,16 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
212214
stabilityCheckTask,
213215
)
214216
}
217+
218+
// Add output parameter to the Kotlin tasks to ensure it is compatible with the Build Cache
219+
target.tasks.withType(KotlinCompile::class.java)
220+
.named { it.contains(variantNameUpperCase) && isKotlinTaskApplicable(it, false) }
221+
.configureEach {
222+
val stabilityDir =
223+
target.layout.buildDirectory.dir("stability/${variant.name}")
224+
.get()
225+
outputs.dir(stabilityDir).optional(true)
226+
}
215227
}
216228

217229
target.afterEvaluate {
@@ -266,10 +278,29 @@ public class StabilityAnalyzerGradlePlugin : KotlinCompilerPluginSupportPlugin {
266278
return project.provider {
267279
val projectDependencies = collectProjectDependencies(project)
268280

281+
val variant =
282+
if (project.extensions.findByType(AndroidComponentsExtension::class.java) != null) {
283+
kotlinCompilation.compileKotlinTaskName
284+
.removePrefix("compile")
285+
.removeSuffix("Kotlin")
286+
.replaceFirstChar { it.lowercase() }
287+
} else {
288+
""
289+
}
290+
291+
val stabilityFolderName = if (variant.isBlank()) {
292+
"stability"
293+
} else {
294+
"stability/$variant"
295+
}
269296
// Write project dependencies to a file to avoid empty string issues with SubpluginOption
270-
val stabilityDir = project.layout.buildDirectory.dir("stability").get().asFile
297+
val stabilityDir = project.layout.buildDirectory.dir(stabilityFolderName).get().asFile
271298
stabilityDir.mkdirs()
272-
val dependenciesFile = java.io.File(stabilityDir, "project-dependencies.txt")
299+
300+
val variantlessStabilityDir = project.layout.buildDirectory.dir("stability").get().asFile
301+
variantlessStabilityDir.mkdirs()
302+
303+
val dependenciesFile = java.io.File(variantlessStabilityDir, "project-dependencies.txt")
273304
dependenciesFile.writeText(projectDependencies.joinToString("\n"))
274305

275306
listOf(

0 commit comments

Comments
 (0)