forked from SUPERCILEX/Robot-Scouter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
139 lines (113 loc) · 4.39 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
import com.android.build.gradle.BaseExtension
import org.apache.commons.io.output.TeeOutputStream
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions
import org.jetbrains.kotlin.gradle.internal.AndroidExtensionsExtension
import org.jetbrains.kotlin.gradle.internal.CacheImplementation
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
Config.run { repositories.deps() }
dependencies {
classpath(Config.Plugins.android)
classpath(Config.Plugins.kotlin)
classpath(Config.Plugins.google)
classpath(Config.Plugins.firebase)
classpath(Config.Plugins.fabric)
}
}
plugins {
id("com.supercilex.robotscouter.build")
`build-scan`
Config.Plugins.run { versionChecker }
}
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
publishAlways()
for (tag in buildTags) tag(tag)
}
allprojects {
Config.run { repositories.deps() }
configureGeneral()
configureKtlint()
configureAndroid()
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
tasks.register<Delete>("clean") {
delete("build")
}
fun Project.configureGeneral() {
val compilerArgs: KotlinCommonToolOptions.() -> Unit = {
freeCompilerArgs = listOf("-progressive")
}
tasks.withType<KotlinCompile>().configureEach { kotlinOptions(compilerArgs) }
tasks.withType<Kotlin2JsCompile>().configureEach { kotlinOptions(compilerArgs) }
}
fun Project.configureKtlint() {
val ktlintConfig = configurations.create("ktlint")
val ktlint = tasks.register<JavaExec>("ktlint") {
if (!file("src").exists()) {
isEnabled = false
return@register
}
main = "com.github.shyiko.ktlint.Main"
classpath = ktlintConfig
args = listOf("src/**/*.kt")
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
// Resource packaging breaks otherwise for some reason
tasks.matching { it.name.contains("Test") }.configureEach { enabled = false }
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")
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
}
}
configure<AndroidExtensionsExtension> {
configure(delegateClosureOf<AndroidExtensionsExtension> { isExperimental = true })
defaultCacheImplementation = CacheImplementation.SPARSE_ARRAY
}
}