-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathbuild.gradle.kts.template
More file actions
176 lines (148 loc) · 4.88 KB
/
Copy pathbuild.gradle.kts.template
File metadata and controls
176 lines (148 loc) · 4.88 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
// This template is the baseline for
// all functional tests executed against the android-junit5 plugin.
// It is based on the Gradle Kotlin DSL (.kts) and provides several additional
// template placeholders markers, which are substituted upon creating virtual projects
// in which the test code is being executed for every supported Android Gradle Plugin.
//
// The individual configuration of each test depends on the config.toml file,
// located in the sub-folder next to its source code.
import com.android.build.api.variant.HasUnitTestBuilder
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
val androidGradlePluginVersion: String = "{{ AGP_VERSION }}"
val kotlinVersion: String = "{{ KOTLIN_VERSION }}"
val junitJupiterVersion: String = "{{ JUNIT_JUPITER_VERSION }}"
val junit5AndroidLibsVersion: String = "{{ JUNIT5_ANDROID_LIBS_VERSION }}"
val javaVersion = JavaVersion.VERSION_17
buildscript {
repositories {
google()
mavenCentral()
maven("https://central.sonatype.com/repository/maven-snapshots") {
mavenContent {
snapshotsOnly()
}
}
}
}
plugins {
id("com.android.application")
{% if USE_KOTLIN %}
{% if atLeastAgp("9.0.0-alpha04") %}
// AGP 9 introduces a built-in Kotlin distribution,
// making it obsolete to declare Kotlin explicitly alongside it
{% else %}
id("org.jetbrains.kotlin.android")
{% endif %}
{% endif %}
{% if USE_JACOCO %}
jacoco
{% endif %}
id("de.mannodermaus.android-junit5")
}
// Double-checking the integrity of the AGP version under test
val version = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (version != "${androidGradlePluginVersion}") {
throw IllegalStateException("Incorrect AGP version. Expected ${androidGradlePluginVersion}, got $version")
}
repositories {
google()
mavenCentral()
maven("https://central.sonatype.com/repository/maven-snapshots") {
mavenContent {
snapshotsOnly()
}
}
}
android {
val minSdkVersion: Int = {{ MIN_SDK_VERSION }}
{% if OVERRIDE_SDK_VERSION %}
val usedCompileSdk: Int = {{ OVERRIDE_SDK_VERSION }}
val usedTargetSdkVersion: Int = {{ OVERRIDE_SDK_VERSION }}
{% else %}
val usedCompileSdk: Int = {{ COMPILE_SDK_VERSION }}
val usedTargetSdkVersion: Int = {{ TARGET_SDK_VERSION }}
{% endif %}
compileSdk = usedCompileSdk
defaultConfig {
namespace = "de.mannodermaus.app"
minSdk = minSdkVersion
targetSdk = usedTargetSdkVersion
{% if INCLUDE_ANDROID_RESOURCES %}
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
{% endif %}
{% if USE_CUSTOM_BUILD_TYPE %}
buildTypes {
register("{{ USE_CUSTOM_BUILD_TYPE }}")
}
{% endif %}
}
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
{% if USE_FLAVORS %}
flavorDimensions.add("environment")
productFlavors {
register("free") {
dimension = "environment"
}
register("paid") {
dimension = "environment"
}
}
{% endif %}
testOptions {
{% if RETURN_DEFAULT_VALUES %}
unitTests.isReturnDefaultValues = true
{% endif %}
{% if INCLUDE_ANDROID_RESOURCES %}
unitTests.isIncludeAndroidResources = true
{% endif %}
// Gradle 6.5 fixed the syntax for UnitTestOptions' DSL
unitTests.all { test ->
test.testLogging {
events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
}
}
}
}
{% if USE_KOTLIN %}
kotlin {
compilerOptions {
jvmTarget = JvmTarget.fromTarget(javaVersion.toString())
}
}
{% endif %}
junitPlatform {
{% if USE_JACOCO %}
jacocoOptions {
html {
enabled.set(true)
destination.set(layout.buildDirectory.dir("reports/jacocoCustom"))
}
}
{% endif %}
}
{% for type in DISABLE_TESTS_FOR_BUILD_TYPES %}
androidComponents {
beforeVariants(selector().withBuildType("{{ type }}")) { variantBuilder ->
(variantBuilder as HasUnitTestBuilder).enableUnitTest = false
}
}
{% end %}
dependencies {
{% if USE_KOTLIN %}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
{% endif %}
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
{% if INCLUDE_ANDROID_RESOURCES %}
androidTestImplementation("androidx.test:runner:1.4.0")
androidTestImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
androidTestImplementation("de.mannodermaus.junit5:android-test-core:${junit5AndroidLibsVersion}")
androidTestRuntimeOnly("de.mannodermaus.junit5:android-test-runner:${junit5AndroidLibsVersion}")
{% endif %}
}