@@ -53,6 +53,7 @@ import org.gradle.internal.os.OperatingSystem
53
53
import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP
54
54
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
55
55
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
56
+ import java.io.File
56
57
import java.util.Locale
57
58
import javax.inject.Inject
58
59
import kotlin.io.encoding.Base64
@@ -97,7 +98,30 @@ public class PaparazziPlugin @Inject constructor(
97
98
project.addTestDependency()
98
99
val layoutlibNativeRuntimeFileCollection = project.setupLayoutlibRuntimeDependency()
99
100
val layoutlibResourcesFileCollection = project.setupLayoutlibResourcesDependency()
100
- val snapshotOutputDir = project.layout.projectDirectory.dir(" src/test/snapshots" )
101
+ val testSourceSetProvider = project.objects.directoryProperty()
102
+ testSourceSetProvider.set(project.layout.projectDirectory.dir(" src/test" ))
103
+
104
+ project.plugins.withId(" org.jetbrains.kotlin.multiplatform" ) {
105
+ val kmpExtension = project.extensions.getByType(KotlinMultiplatformExtension ::class .java)
106
+ kmpExtension.sourceSets.all { sourceSet ->
107
+ if (sourceSet.name == " androidUnitTest" || sourceSet.name == " androidTest" ) {
108
+ testSourceSetProvider.set(
109
+ sourceSet.kotlin.srcDirs.map {
110
+ File (it.parent)
111
+ }.firstOrNull()
112
+ )
113
+ }
114
+ }
115
+ }
116
+
117
+ val defaultUnitTestDir = project.layout.projectDirectory.dir(" src/test" )
118
+ val snapshotOutputDir = testSourceSetProvider.map {
119
+ if (it.asFile.exists() && ! defaultUnitTestDir.asFile.exists()) {
120
+ it.dir(" snapshots" )
121
+ } else {
122
+ defaultUnitTestDir.dir(" snapshots" )
123
+ }
124
+ }
101
125
102
126
// Create anchor tasks for all variants.
103
127
val verifyVariants = project.tasks.register(" verifyPaparazzi" ) {
@@ -216,7 +240,7 @@ public class PaparazziPlugin @Inject constructor(
216
240
test.systemProperties[" paparazzi.project.dir" ] = projectDirectory.toString()
217
241
test.systemProperties[" paparazzi.build.dir" ] = buildDirectory.get().toString()
218
242
test.systemProperties[" paparazzi.report.dir" ] = reportOutputDir.get().toString()
219
- test.systemProperties[" paparazzi.snapshot.dir" ] = snapshotOutputDir.toString()
243
+ test.systemProperties[" paparazzi.snapshot.dir" ] = snapshotOutputDir.get(). toString()
220
244
test.systemProperties[" paparazzi.artifacts.cache.dir" ] = gradleUserHomeDir.path
221
245
test.systemProperties.putAll(project.properties.filterKeys { it.startsWith(" app.cash.paparazzi" ) })
222
246
@@ -241,19 +265,15 @@ public class PaparazziPlugin @Inject constructor(
241
265
242
266
test.inputs.dir(
243
267
isVerifyRun.flatMap {
244
- project.objects.directoryProperty().apply {
245
- set(if (it) snapshotOutputDir else null )
246
- }
268
+ if (it) snapshotOutputDir else project.objects.directoryProperty()
247
269
}
248
270
).withPropertyName(" paparazzi.snapshot.input.dir" )
249
271
.withPathSensitivity(PathSensitivity .RELATIVE )
250
272
.optional()
251
273
252
274
test.outputs.dir(
253
275
isRecordRun.flatMap {
254
- project.objects.directoryProperty().apply {
255
- set(if (it) snapshotOutputDir else null )
256
- }
276
+ if (it) snapshotOutputDir else project.objects.directoryProperty()
257
277
}
258
278
).withPropertyName(" paparazzi.snapshots.output.dir" )
259
279
.optional()
0 commit comments