| author | Da Risk <da_risk@geekorum.com> |
| Tue, 05 May 2026 14:55:56 -0400 | |
| changeset 119 | 684356cd6a7d |
| parent 114 | ab226603d0f5 |
| permissions | -rw-r--r-- |
| 0 | 1 |
/* |
2 |
* AboutOss is a utility library to retrieve and display |
|
3 |
* opensource licenses in Android applications. |
|
4 |
* |
|
|
34
ce299aacc068
build: update license headers
Da Risk <da_risk@geekorum.com>
parents:
22
diff
changeset
|
5 |
* Copyright (C) 2023-2025 by Frederic-Charles Barthelery. |
| 0 | 6 |
* |
7 |
* This file is part of AboutOss. |
|
8 |
* |
|
9 |
* AboutOss is free software: you can redistribute it and/or modify |
|
10 |
* it under the terms of the GNU General Public License as published by |
|
11 |
* the Free Software Foundation, either version 3 of the License, or |
|
12 |
* (at your option) any later version. |
|
13 |
* |
|
14 |
* AboutOss is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with AboutOss. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
*/ |
|
22 |
package com.geekorum.build |
|
23 |
||
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
24 |
import com.android.build.api.dsl.ApplicationExtension |
| 0 | 25 |
import com.android.build.api.dsl.CommonExtension |
26 |
import com.android.build.api.dsl.DefaultConfig |
|
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
27 |
import com.android.build.api.dsl.LibraryExtension |
| 0 | 28 |
import com.android.build.gradle.BaseExtension |
29 |
import com.android.build.gradle.internal.dsl.TestOptions |
|
30 |
import org.gradle.api.Project |
|
31 |
import org.gradle.api.artifacts.Dependency |
|
32 |
import org.gradle.api.artifacts.DependencyConstraint |
|
33 |
import org.gradle.api.artifacts.ExternalModuleDependency |
|
34 |
import org.gradle.api.artifacts.dsl.DependencyConstraintHandler |
|
35 |
import org.gradle.api.artifacts.dsl.DependencyHandler |
|
36 |
import org.gradle.kotlin.dsl.closureOf |
|
37 |
import org.gradle.kotlin.dsl.configure |
|
38 |
import org.gradle.kotlin.dsl.dependencies |
|
39 |
import org.gradle.kotlin.dsl.kotlin |
|
40 |
||
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
41 |
const val espressoVersion = "3.6.1" |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
42 |
const val androidxTestRunnerVersion = "1.6.2" |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
43 |
const val androidxTestCoreVersion = "1.6.1" |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
44 |
const val robolectricVersion = "4.14.1" |
| 0 | 45 |
|
46 |
||
47 |
/* |
|
48 |
* Configuration for espresso and robolectric usage in an Android project |
|
49 |
*/ |
|
50 |
internal fun Project.configureTests() {
|
|
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
51 |
extensions.configure<CommonExtension>("android") {
|
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
52 |
if (this is ApplicationExtension) {
|
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
53 |
defaultConfig {
|
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
54 |
testInstrumentationRunner = "com.geekorum.ttrss.HiltRunner" |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
55 |
testInstrumentationRunnerArguments += mapOf( |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
56 |
"clearPackageData" to "true", |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
57 |
"disableAnalytics" to "true" |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
58 |
) |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
59 |
} |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
60 |
} |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
61 |
if (this is LibraryExtension) {
|
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
62 |
defaultConfig {
|
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
63 |
testInstrumentationRunner = "com.geekorum.ttrss.HiltRunner" |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
64 |
testInstrumentationRunnerArguments += mapOf( |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
65 |
"clearPackageData" to "true", |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
66 |
"disableAnalytics" to "true" |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
67 |
) |
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
68 |
} |
| 0 | 69 |
} |
70 |
||
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
71 |
testOptions.apply {
|
| 0 | 72 |
execution = "ANDROIDX_TEST_ORCHESTRATOR" |
73 |
animationsDisabled = true |
|
74 |
||
75 |
unitTests {
|
|
76 |
isIncludeAndroidResources = true |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
dependencies {
|
|
82 |
dualTestImplementation(kotlin("test-junit"))
|
|
83 |
||
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
84 |
androidTestUtil("androidx.test:orchestrator:1.5.1")
|
| 0 | 85 |
androidTestImplementation("androidx.test:runner:$androidxTestRunnerVersion")
|
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
86 |
dualTestImplementation("androidx.test.ext:junit-ktx:1.2.1")
|
| 0 | 87 |
|
88 |
dualTestImplementation("androidx.test:core-ktx:$androidxTestCoreVersion")
|
|
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
89 |
dualTestImplementation("androidx.test:rules:1.6.1")
|
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
90 |
|
| 0 | 91 |
// fragment testing is usually declared on debugImplementation configuration and need these dependencies |
92 |
constraints {
|
|
93 |
debugImplementation("androidx.test:core:$androidxTestCoreVersion")
|
|
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
94 |
debugImplementation("androidx.test:monitor:1.7.2")
|
| 0 | 95 |
} |
96 |
||
97 |
dualTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion")
|
|
98 |
dualTestImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion")
|
|
99 |
dualTestImplementation("androidx.test.espresso:espresso-intents:$espressoVersion")
|
|
100 |
||
101 |
// assertions |
|
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
102 |
dualTestImplementation("com.google.truth:truth:1.4.4")
|
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
103 |
dualTestImplementation("androidx.test.ext:truth:1.6.0")
|
| 0 | 104 |
|
105 |
// mock |
|
|
114
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
106 |
testImplementation("io.mockk:mockk:1.13.8")
|
|
ab226603d0f5
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
34
diff
changeset
|
107 |
androidTestImplementation("io.mockk:mockk-android:1.13.8")
|
| 0 | 108 |
testImplementation("org.robolectric:robolectric:$robolectricVersion")
|
109 |
||
110 |
constraints {
|
|
111 |
dualTestImplementation(kotlin("reflect")) {
|
|
112 |
because("Use the kotlin version that we use")
|
|
113 |
} |
|
114 |
androidTestImplementation("org.objenesis:objenesis") {
|
|
115 |
because("3.x version use instructions only available with minSdk 26 (Android O)")
|
|
116 |
version {
|
|
117 |
strictly("2.6")
|
|
118 |
} |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any) {
|
|
125 |
add("androidTestImplementation", dependencyNotation)
|
|
126 |
add("testImplementation", dependencyNotation)
|
|
127 |
} |
|
128 |
||
129 |
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
|
|
130 |
val closure = closureOf(action) |
|
131 |
add("androidTestImplementation", dependencyNotation, closure)
|
|
132 |
add("testImplementation", dependencyNotation, closure)
|
|
133 |
} |
|
134 |
||
135 |
internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any): Dependency? = |
|
136 |
add("androidTestImplementation", dependencyNotation)
|
|
137 |
||
138 |
internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
|
|
139 |
val closure = closureOf(action) |
|
140 |
add("androidTestImplementation", dependencyNotation, closure)
|
|
141 |
} |
|
142 |
||
143 |
internal fun DependencyHandler.androidTestUtil(dependencyNotation: Any): Dependency? = |
|
144 |
add("androidTestUtil", dependencyNotation)
|
|
145 |
||
146 |
internal fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? = |
|
147 |
add("testImplementation", dependencyNotation)
|
|
148 |
||
149 |
internal fun DependencyConstraintHandler.debugImplementation(dependencyConstraintNotation: Any): DependencyConstraint? = |
|
150 |
add("debugImplementation", dependencyConstraintNotation)
|