-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathbuild.gradle
118 lines (95 loc) · 4.02 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
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-parcelize'
buildscript {
def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.6.0" }
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()
}
}
def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 31 }
def computeBuildToolsVersion = { ->
project.hasProperty("buildToolsVersion") ? buildToolsVersion : "31.0.0"
}
android {
applyBeforePluginGradleConfiguration()
compileSdkVersion computeCompileSdkVersion()
buildToolsVersion computeBuildToolsVersion()
defaultConfig {
targetSdkVersion 31
versionCode 1
versionName "1.0"
}
}
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
}
}