forked from igorwojda/android-showcase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
116 lines (98 loc) · 3.99 KB
/
build.gradle.kts
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
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
plugins {
id(GradlePluginId.DETEKT)
id(GradlePluginId.KTLINT_GRADLE)
id(GradlePluginId.GRADLE_VERSION_PLUGIN)
id(GradlePluginId.KOTLIN_JVM) apply false
id(GradlePluginId.KOTLIN_ANDROID) apply false
id(GradlePluginId.KOTLIN_ANDROID_EXTENSIONS) apply false
id(GradlePluginId.ANDROID_APPLICATION) apply false
id(GradlePluginId.ANDROID_DYNAMIC_FEATURE) apply false
id(GradlePluginId.ANDROID_LIBRARY) apply false
id(GradlePluginId.SAFE_ARGS) apply false
}
// all projects = root project + sub projects
allprojects {
repositories {
google()
jcenter()
}
// We want to apply ktlint at all project level because it also checks build gradle files
apply(plugin = GradlePluginId.KTLINT_GRADLE)
// Ktlint configuration for sub-projects
ktlint {
version.set(CoreVersion.KTLINT)
verbose.set(true)
android.set(true)
// Uncomment below line and run .\gradlew ktlintCheck to see check ktlint experimental rules
// enableExperimentalRules.set(true)
reporters {
reporter(ReporterType.CHECKSTYLE)
}
filter {
exclude { element -> element.file.path.contains("generated/") }
}
}
}
subprojects {
tasks.withType<Test> {
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
}
apply(plugin = GradlePluginId.DETEKT)
detekt {
config = files("${project.rootDir}/detekt.yml")
parallel = true
}
}
// JVM target applied to all Kotlin tasks across all sub-projects
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
}
tasks {
// Gradle versions plugin configuration
"dependencyUpdates"(DependencyUpdatesTask::class) {
resolutionStrategy {
componentSelection {
all {
// Do not show pre-release version of library in generated dependency report
val rejected = listOf("alpha", "beta", "rc", "cr", "m", "preview")
.map { qualifier -> Regex("(?i).*[.-]$qualifier[.\\d-]*") }
.any { it.matches(candidate.version) }
if (rejected) {
reject("Release candidate")
}
// kAndroid newest version is 0.8.8 (jcenter), however maven repository contains version 0.8.7 and
// plugin fails to recognize it correctly
if (candidate.group == "com.pawegio.kandroid") {
reject("version ${candidate.version} is broken for ${candidate.group}'")
}
}
}
}
}
}
task("staticCheck") {
description =
"""Mimics all static checks that run on CI.
Note that this task is intended to run locally (not on CI), because on CI we prefer to have parallel execution
and separate reports for each check (multiple statuses eg. on github PR page).
""".trimMargin()
group = "verification"
afterEvaluate {
// Filter modules with "lintDebug" task (non-Android modules do not have lintDebug task)
val lintTasks = subprojects.mapNotNull { "${it.name}:lintDebug" }
// Get modules with "testDebugUnitTest" task (app module does not have it)
val testTasks = subprojects.mapNotNull { "${it.name}:testDebugUnitTest" }
.filter { it != "app:testDebugUnitTest" }
// All task dependencies
val taskDependencies =
mutableListOf("app:assembleAndroidTest", "ktlintCheck", "detekt").also {
it.addAll(lintTasks)
it.addAll(testTasks)
}
// By defining Gradle dependency all dependent tasks will run before this "empty" task
dependsOn(taskDependencies)
}
}