forked from proxer/ProxerAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
executable file
·286 lines (227 loc) · 8.13 KB
/
build.gradle
File metadata and controls
executable file
·286 lines (227 loc) · 8.13 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import groovy.io.FileType
buildscript {
apply from: 'gradle/versions.gradle'
apply from: 'gradle/dependencies.gradle'
repositories {
jcenter()
google()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
dependencies {
classpathDependencies.values().each { classpath it }
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'com.novoda.android-command'
android {
compileSdkVersion project.ext.compileSdkVersion
dexOptions {
preDexLibraries !isCI()
}
compileOptions {
sourceCompatibility project.ext.javaVersion
targetCompatibility project.ext.javaVersion
}
defaultConfig {
applicationId 'me.proxer.app'
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion
versionCode project.ext.appVersionMajor * 1000000 + project.ext.appVersionMinor * 10000 + project.ext.appVersionPatch * 100
versionName "${project.ext.appVersionMajor}.${project.ext.appVersionMinor}.${project.ext.appVersionPatch}"
vectorDrawables.useSupportLibrary true
resConfigs 'de'
}
signingConfigs {
if (shouldSign()) {
release {
storeFile file(getFromSecrets('RELEASE_STORE_FILE'))
storePassword getFromSecrets('RELEASE_STORE_PASSWORD')
keyAlias getFromSecrets('RELEASE_KEY_ALIAS')
keyPassword getFromSecrets('RELEASE_KEY_PASSWORD')
}
}
}
buildTypes {
boolean shouldSign = shouldSign() && !isCI()
if (!shouldSign) {
logger.warn('This build will not be signed because it is missing the keystore info. Please add ' +
'values for "RELEASE_STORE_FILE", "RELEASE_STORE_PASSWORD", "RELEASE_KEY_ALIAS" and ' +
'"RELEASE_KEY_PASSWORD" to your secrets.properties file if you want the apk to be signed.')
}
debug {
multiDexEnabled true
multiDexKeepProguard file('config/multidex/multidex-config.pro')
archivesBaseName = "app-${defaultConfig.versionName}"
buildConfigField 'String', 'PROXER_API_KEY', "\"${getFromSecrets('PROXER_API_KEY')}\""
buildConfigField 'boolean', 'STORE', "false"
}
release {
postprocessing {
removeUnusedCode true
removeUnusedResources true
obfuscate true
optimizeCode true
getProguardFiles().add(0, file('config/proguard/proguard-rules.pro'))
}
archivesBaseName = "app-${defaultConfig.versionName}"
buildConfigField 'String', 'PROXER_API_KEY', "\"${getFromSecrets('PROXER_API_KEY')}\""
buildConfigField 'boolean', 'STORE', "false"
if (shouldSign) {
signingConfig signingConfigs.release
}
}
storeRelease {
postprocessing {
removeUnusedCode true
removeUnusedResources true
obfuscate true
optimizeCode true
getProguardFiles().add(0, file('config/proguard/proguard-rules.pro'))
}
archivesBaseName = "app-${defaultConfig.versionName}"
buildConfigField 'String', 'PROXER_API_KEY', "\"${getFromSecrets('PROXER_API_KEY')}\""
buildConfigField 'boolean', 'STORE', "true"
if (shouldSign) {
signingConfig signingConfigs.release
}
}
}
lintOptions {
warningsAsErrors = true
lintConfig new File(rootDir, 'config/lint/lint.xml')
}
packagingOptions {
exclude '**/*.kotlin_builtins'
exclude '**/*.kotlin_module'
exclude '**/rxkotlin.properties'
exclude '**/*.pro'
}
sourceSets {
main {
main.java.srcDirs += 'src/main/kotlin'
debug.java.srcDirs += 'src/debug/kotlin'
res.srcDirs += getResSrcDirs()
}
}
}
configurations {
ktlint
}
repositories {
jcenter()
google()
maven { url 'https://jitpack.io' }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
implementationDependencies.values().each { implementation it }
debugImplementationDependencies.values().each { debugImplementation it }
releaseImplementationDependencies.values().each { releaseImplementation it }
releaseImplementationDependencies.values().each { storeReleaseImplementation it }
compileOnlyDependencies.values().each { compileOnly it }
kaptDependencies.values().each { kapt it }
ktlintDependencies.values().each { ktlint it }
transitiveImplementationDependencies.values().each {
implementation(it) {
transitive = true
}
}
excludingImplementationDependencies.values().each { dependency ->
implementation(dependency.dependency) {
dependency.exclusions.each {
exclude module: it
}
}
}
}
task ktlintCheck(type: Exec) {
group 'Verification'
description 'Analyze your kotlin code with ktlint.'
commandLine 'java', '-cp', configurations.ktlint.join(System.getProperty('path.separator')),
'com.github.shyiko.ktlint.Main', '--reporter=checkstyle', 'src/**/*.kt'
ignoreExitValue = true
doFirst {
File outputFile = new File(buildDir, 'reports/ktlint/ktlint-checkstyle.xml')
outputFile.parentFile.mkdirs()
outputFile.createNewFile()
standardOutput = new FileOutputStream(outputFile)
}
doLast {
standardOutput.close()
if (execResult.exitValue != 0) {
throw new GradleException("ktlint finished with non-zero exit value ${execResult.exitValue}")
}
}
}
task ktlintFormat(type: Exec) {
group 'Formatting'
description = "Fix Kotlin code style deviations."
commandLine 'java', '-cp', configurations.ktlint.join(System.getProperty('path.separator')),
'com.github.shyiko.ktlint.Main', '-F', 'src/**/*.kt'
}
task wrapper(type: Wrapper) {
gradleVersion project.ext.gradleVersion
}
kapt {
useBuildCache = true
}
detekt {
version = detektPluginVersion
profile('main') {
config = "$projectDir/config/detekt/detekt.yml"
output = "$buildDir/reports/detekt"
parallel = true
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
}
}
gradle.projectsEvaluated {
check.dependsOn detektCheck
check.dependsOn ktlintCheck
}
static getResSrcDirs() {
String layoutsPath = 'src/main/res/layouts'
Set<String> result = []
new File(layoutsPath).eachFile(FileType.DIRECTORIES) {
result.add("${layoutsPath}/${it.name}")
}
return result
}
static String getFromSecrets(String key) {
if (isCI()) {
return 'dummy'
}
Properties result = new Properties()
try {
result.load(new FileInputStream(new File('secrets.properties')))
} catch (Exception ignored) {
throw new GradleException("Please add a secrets.properties file with a value for $key to perform this action.")
}
if (!result.containsKey(key)) {
throw new GradleException("Please include a value for $key in your secrets.properties file to perform this action.")
}
return result[key]
}
static boolean shouldSign() {
Properties result = new Properties()
try {
result.load(new FileInputStream(new File('secrets.properties')))
} catch (Exception ignored) {
return false
}
return result.containsKey('RELEASE_STORE_FILE') && result.containsKey('RELEASE_STORE_PASSWORD') &&
result.containsKey('RELEASE_KEY_ALIAS') && result.containsKey('RELEASE_KEY_PASSWORD')
}
static boolean isCI() {
Object isCI = System.getenv('CI')
return isCI != null && isCI.toBoolean()
}