๐Ÿ“ฆ airbnb / Showkase

๐Ÿ“„ build.gradle ยท 165 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165buildscript {
    repositories {
        mavenCentral()
        google()
    }
}

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'app.cash.paparazzi' version "1.2.0"
}

if (project.hasProperty('useKsp')) {
    apply plugin: 'com.google.devtools.ksp'
} else {
    apply plugin: 'kotlin-kapt'
    kapt {
        correctErrorTypes = true
    }
}

android {
    namespace "com.airbnb.android.showkase.screenshot.testing.paparazzi"
    // Added to avoid this error -
    // Execution failed for task ':showkase-processor-testing:mergeDebugAndroidTestJavaResource'.
    // > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
    // > More than one file was found with OS independent path 'META-INF/gradle/incremental.annotation.processors'
    packagingOptions {
        exclude 'META-INF/gradle/incremental.annotation.processors'
        exclude("META-INF/*.kotlin_module")
    }
    defaultConfig {
        minSdkVersion 21
        compileSdk 36
        targetSdkVersion 33
        // The following argument makes the Android Test Orchestrator run its
        // "pm clear" command after each test invocation. This command ensures
        // that the app's state is completely cleared between tests.
        testInstrumentationRunnerArguments clearPackageData: 'true'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerVersion "${versions.kotlinCompilerVersion}"
        kotlinCompilerExtensionVersion "${versions.composeCompiler}"
    }
    // Added to avoid this error -
    // Execution failed for task ':app:mergeDebugAndroidTestJavaResource'.
    // > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
    // > 2 files found with path 'META-INF/AL2.0' from inputs:
    packagingOptions {
        exclude 'META-INF/AL2.0'
        exclude 'META-INF/LGPL2.1'
    }
}

// https://github.com/cashapp/paparazzi/issues/409
tasks.withType(Test).configureEach { task ->
    task.jvmArgs += [
            "--add-opens=java.base/java.lang=ALL-UNNAMED",
            "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
            "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
    ]
}

afterEvaluate {
    /**
     * KSP does not currently register kotlin generated sources.
     * https://github.com/google/ksp/issues/37
     */
    if (project.extensions.findByType(com.android.build.gradle.LibraryExtension.class) != null) {
        project.android.libraryVariants.all { variant ->
            def variantName = variant.name
            def outputFolder = new File("build/generated/ksp/$variantName/kotlin")
            variant.addJavaSourceFoldersToModel(outputFolder)
            android.sourceSets.getAt(variantName).java {
                srcDir(outputFolder)
            }

            // Register the generated unit test sources as well
            // Note, there is a nuanced different between the name of the directory on disk and the source set name
            // in AGP.
            // eg "debugUnitTest"
            def testDirectoryName = "${variantName}UnitTest"
            // eg "testDebug"
            def testSourceSetName = "test${variantName.capitalize()}"

            // Not every module will have test sources, so finding it is optional.
            android.sourceSets.findByName(testSourceSetName)?.kotlin {
                def testOutputFolder = new File("build/generated/ksp/$testDirectoryName/kotlin")
                srcDir(testOutputFolder)
            }
        }
    } else if (project.extensions.findByType(com.android.build.gradle.AbstractAppExtension.class) != null) {
        project.android.applicationVariants.all { variant ->
            def variantName = variant.name
            def outputFolder = new File("build/generated/ksp/$variantName/kotlin")
            variant.addJavaSourceFoldersToModel(outputFolder)
            android.sourceSets.getAt(variantName).java {
                srcDir(outputFolder)
            }

            // Register the generated unit test sources as well
            // Note, there is a nuanced different between the name of the directory on disk and the source set name
            // in AGP.
            // eg "debugUnitTest"
            def testDirectoryName = "${variantName}UnitTest"
            // eg "testDebug"
            def testSourceSetName = "test${variantName.capitalize()}"

            // Not every module will have test sources, so finding it is optional.
            android.sourceSets.findByName(testSourceSetName)?.kotlin {
                def testOutputFolder = new File("build/generated/ksp/$testDirectoryName/kotlin")
                srcDir(testOutputFolder)
            }
        }
    }
}

dependencies {
    // Showkase
    implementation project(':showkase')
    if (project.hasProperty('useKsp')) {
        ksp project(':showkase-processor')
        kspAndroidTest project(':showkase-processor')
        kspTest project(':showkase-processor')
    } else {
        kapt project(':showkase-processor')
        kaptAndroidTest project(':showkase-processor')
        kaptTest project(':showkase-processor')
    }
    api project(':showkase-screenshot-testing')

    // Compose
    implementation deps.compose.activityCompose
    implementation deps.compose.composeRuntime
    implementation deps.compose.constraintLayout
    implementation deps.compose.core
    implementation deps.compose.foundation
    implementation deps.compose.tooling
    implementation deps.compose.layout
    implementation deps.compose.material
    implementation deps.compose.savedInstanceState
    implementation deps.compose.uiLiveData

    // Image loading
    implementation deps.imageLoading.picasso

    // Testing
    testImplementation deps.test.junit
    testImplementation deps.test.junitImplementation
    implementation deps.test.testParameterInjector
    testImplementation deps.compose.uiTest
    testImplementation project(':showkase-screenshot-testing-paparazzi')
}