-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
build.gradle.kts
148 lines (121 loc) · 4.57 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
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
import com.android.build.gradle.BaseExtension
import org.apache.commons.io.output.TeeOutputStream
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.internal.AndroidExtensionsExtension
import org.jetbrains.kotlin.gradle.internal.CacheImplementation
buildscript {
repositories.deps()
dependencies {
classpath(Config.Plugins.android)
classpath(Config.Plugins.kotlin)
classpath(Config.Plugins.google)
classpath(Config.Plugins.firebase)
classpath(Config.Plugins.fabric)
}
}
plugins {
`lifecycle-base`
id("com.supercilex.robotscouter.build")
Config.Plugins.run { versionChecker }
}
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
publishAlways()
for (tag in buildTags) tag(tag)
}
allprojects {
repositories.deps()
configureGeneral()
configureKtlint()
configureAndroid()
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
fun Project.configureGeneral() {
afterEvaluate {
convention.findByType<KotlinProjectExtension>()?.apply {
sourceSets.configureEach {
languageSettings.progressiveMode = true
languageSettings.enableLanguageFeature("NewInference")
languageSettings.useExperimentalAnnotation(
"kotlinx.coroutines.ExperimentalCoroutinesApi")
}
}
}
}
fun Project.configureKtlint() {
val ktlintConfig = configurations.create("ktlint")
val ktlint = tasks.register<JavaExec>("ktlint") {
if (!file("src").exists()) {
isEnabled = false
return@register
}
main = "com.pinterest.ktlint.Main"
classpath = ktlintConfig
args = listOf("src/**/*.kt")
maxHeapSize = "100m"
val output = File(buildDir, "reports/ktlint/log.txt")
inputs.dir(fileTree("src").apply { include("**/*.kt") })
outputs.file(output)
outputs.cacheIf { true }
doFirst { standardOutput = TeeOutputStream(standardOutput, output.outputStream()) }
}
tasks.matching { it.name == "check" }.configureEach { dependsOn(ktlint) }
dependencies { "ktlint"(Config.Plugins.ktlint) }
}
fun Project.configureAndroid() {
configurations.register("compileClasspath") // TODO see https://youtrack.jetbrains.com/issue/KT-27170
val tree = (group as String).split(".")
when {
tree.contains("library") && name != "common" -> apply(plugin = "com.android.library")
name == "android-base" -> apply(plugin = "com.android.application")
tree.contains("feature") -> apply(plugin = "com.android.dynamic-feature")
else -> return
}
apply(plugin = "kotlin-android")
apply(plugin = "kotlin-android-extensions")
// Resource packaging breaks otherwise for some reason
tasks.matching { it.name.contains("Test") }.configureEach { enabled = false }
if (!isReleaseBuild) {
tasks.matching { it.name.contains("lintVitalRelease") }.configureEach { enabled = false }
}
configure<BaseExtension> {
compileSdkVersion(Config.SdkVersions.compile)
defaultConfig {
minSdkVersion(Config.SdkVersions.min)
targetSdkVersion(Config.SdkVersions.target)
versionCode = 1
vectorDrawables.useSupportLibrary = true
}
lintOptions {
isCheckDependencies = true
isCheckAllWarnings = true
isWarningsAsErrors = true
isAbortOnError = false
baseline(file("$rootDir/app/android-base/lint-baseline.xml"))
disable(
"InvalidPackage", // Needed because of Okio
"GradleDependency", "NewerVersionAvailable", // For build reproducibility
"WrongThreadInterprocedural", // Slow
"SyntheticAccessor" // Don't care, proguard should deal with it
)
val reportsDir = "$buildDir/reports"
htmlOutput = file("$reportsDir/lint-results.html")
xmlOutput = file("$reportsDir/lint-results.xml")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
(this as ExtensionAware).configure<KotlinJvmOptions> {
jvmTarget = "1.8"
}
}
configure<AndroidExtensionsExtension> {
isExperimental = true
defaultCacheImplementation = CacheImplementation.SPARSE_ARRAY
}
}