-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathbuild.gradle
158 lines (134 loc) · 6.06 KB
/
build.gradle
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
import groovy.json.JsonSlurper
import org.gradle.internal.logging.text.StyledTextOutputFactory
import static org.gradle.internal.logging.text.StyledTextOutput.Style
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.4.21" }
def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 28 as int }
def computeTargetSdkVersion = { -> project.hasProperty("targetSdk") ? targetSdk : 28 as int }
def computeBuildToolsVersion = { ->
project.hasProperty("buildToolsVersion") ? buildToolsVersion : "28.0.3" as String
}
buildscript {
def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.4.21" }
def kotlinVersion = computeKotlinVersion()
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:{{runtimeAndroidPluginVersion}}'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
// Set up styled logger
project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger")
// todo: pass appResourcesPath from CLI as a gradle arg
project.ext.getAppResourcesPath = { ->
def relativePathToApp = "app"
def relativePathToAppResources
def absolutePathToAppResources
def projectRoot = "$rootDir/../../.."
def nsConfigFile = file("$projectRoot/nsconfig.json")
def nsConfig
if (nsConfigFile.exists()) {
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
}
if(nsConfig != null && nsConfig.appPath != null){
relativePathToApp = nsConfig.appPath
}
if(nsConfig != null && nsConfig.appResourcesPath != null ) {
relativePathToAppResources = nsConfig.appResourcesPath
} else {
relativePathToAppResources = "$relativePathToApp/App_Resources"
}
absolutePathToAppResources = java.nio.file.Paths.get(projectRoot).resolve(relativePathToAppResources).toAbsolutePath()
project.ext.appResourcesPath = absolutePathToAppResources
return absolutePathToAppResources
}
def applyBuildScriptConfigurations = { ->
def absolutePathToAppResources = getAppResourcesPath()
def pathToBuildScriptGradle = "$absolutePathToAppResources/Android/buildscript.gradle"
def buildScriptGradle = file(pathToBuildScriptGradle)
if (buildScriptGradle.exists()) {
outLogger.withStyle(Style.SuccessHeader).println "\t ~ applying user-defined buildscript from ${buildScriptGradle}"
apply from: pathToBuildScriptGradle, to: buildscript
}
def pathToPluginBuildScriptGradle = "$rootDir/buildscript.gradle"
def pluginBuildScriptGradle = file(pathToPluginBuildScriptGradle)
if (pluginBuildScriptGradle.exists()) {
outLogger.withStyle(Style.SuccessHeader).println "\t ~ applying user-defined buildscript from dependency ${pluginBuildScriptGradle}"
apply from: pathToPluginBuildScriptGradle, to: buildscript
}
}
applyBuildScriptConfigurations()
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
}
}
android {
kotlinOptions {
jvmTarget = '1.8'
}
applyBeforePluginGradleConfiguration()
compileSdkVersion computeCompileSdkVersion()
buildToolsVersion computeBuildToolsVersion()
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
targetSdkVersion computeTargetSdkVersion()
versionCode 1
versionName "1.0"
}
}
dependencies {
def androidXMultidexVersion = project.hasProperty("androidXMultidexVersion") ? project.androidXMultidexVersion : "2.0.1"
def androidxVersion = project.hasProperty("androidxVersion") ? project.androidxVersion : "1.2.0"
def androidXAppCompatVersion = project.hasProperty("androidXAppCompat") ? project.androidXAppCompat : "1.3.1"
def kotlinVersion = computeKotlinVersion()
implementation "androidx.multidex:multidex:$androidXMultidexVersion"
implementation "androidx.core:core:$androidxVersion"
implementation "androidx.appcompat:appcompat:$androidXAppCompatVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
}
def applyBeforePluginGradleConfiguration() {
def appResourcesPath = getAppResourcesPath()
def pathToBeforePluginGradle = "$appResourcesPath/Android/before-plugins.gradle"
def beforePluginGradle = file(pathToBeforePluginGradle)
if (beforePluginGradle.exists()) {
outLogger.withStyle(Style.SuccessHeader).println "\t ~ applying user-defined configuration from ${beforePluginGradle}"
apply from: pathToBeforePluginGradle
}
}
afterEvaluate {
def generateBuildConfig = project.hasProperty("generateBuildConfig") ? project.generateBuildConfig : false
def generateR = project.hasProperty("generateR") ? project.generateR : false
generateReleaseBuildConfig.enabled = generateBuildConfig
generateDebugBuildConfig.enabled = generateBuildConfig
generateReleaseResValues.enabled = generateR
generateDebugResValues.enabled = generateR
}
tasks.whenTaskAdded({ DefaultTask currentTask ->
if (currentTask.name == 'bundleRelease' || currentTask.name == 'bundleDebug') {
def generateBuildConfig = project.hasProperty("generateBuildConfig") ? project.generateBuildConfig : false
def generateR = project.hasProperty("generateR") ? project.generateR : false
if (!generateBuildConfig) {
currentTask.exclude '**/BuildConfig.class'
}
if (!generateR) {
currentTask.exclude '**/R.class', '**/R$*.class'
}
}
})