Skip to content

Commit 37e2dbb

Browse files
authored
feat(plugins): allow plugins to use kotlin files (#5555)
1 parent db53037 commit 37e2dbb

File tree

1 file changed

+56
-30
lines changed

1 file changed

+56
-30
lines changed

vendor/gradle-plugin/build.gradle

+56-30
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,72 @@
11
import groovy.json.JsonSlurper
22

3+
apply plugin: 'com.android.library'
4+
apply plugin: 'kotlin-android'
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
38
buildscript {
9+
def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.4.21" }
10+
def kotlinVersion = computeKotlinVersion()
411
repositories {
512
google()
613
jcenter()
714
}
815
dependencies {
916
classpath 'com.android.tools.build:gradle:{{runtimeAndroidPluginVersion}}'
17+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
1018

1119
// NOTE: Do not place your application dependencies here; they belong
1220
// in the individual module build.gradle files
1321
}
22+
23+
project.ext.getAppResourcesPath = { ->
24+
def relativePathToApp = "app"
25+
def relativePathToAppResources
26+
def absolutePathToAppResources
27+
def projectRoot = "$rootDir/../../.."
28+
def nsConfigFile = file("$projectRoot/nsconfig.json")
29+
def nsConfig
30+
31+
if (nsConfigFile.exists()) {
32+
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
33+
}
34+
35+
if(nsConfig != null && nsConfig.appPath != null){
36+
relativePathToApp = nsConfig.appPath
37+
}
38+
39+
if(nsConfig != null && nsConfig.appResourcesPath != null ) {
40+
relativePathToAppResources = nsConfig.appResourcesPath
41+
} else {
42+
relativePathToAppResources = "$relativePathToApp/App_Resources"
43+
}
44+
45+
absolutePathToAppResources = java.nio.file.Paths.get(projectRoot).resolve(relativePathToAppResources).toAbsolutePath()
46+
47+
project.ext.appResourcesPath = absolutePathToAppResources
48+
49+
return absolutePathToAppResources
50+
}
51+
52+
def applyBuildScriptConfigurations = { ->
53+
def absolutePathToAppResources = getAppResourcesPath()
54+
def pathToBuildScriptGradle = "$absolutePathToAppResources/Android/buildscript.gradle"
55+
def buildScriptGradle = file(pathToBuildScriptGradle)
56+
if (buildScriptGradle.exists()) {
57+
outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined buildscript from ${buildScriptGradle}"
58+
apply from: pathToBuildScriptGradle, to: buildscript
59+
}
60+
61+
def pathToPluginBuildScriptGradle = "$rootDir/buildscript.gradle"
62+
def pluginBuildScriptGradle = file(pathToPluginBuildScriptGradle)
63+
if (pluginBuildScriptGradle.exists()) {
64+
outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined buildscript from dependency ${pluginBuildScriptGradle}"
65+
apply from: pathToPluginBuildScriptGradle, to: buildscript
66+
}
67+
}
68+
applyBuildScriptConfigurations()
69+
1470
}
1571

1672
allprojects {
@@ -25,7 +81,6 @@ allprojects {
2581
}
2682
}
2783

28-
apply plugin: 'com.android.library'
2984

3085
def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 28 }
3186
def computeBuildToolsVersion = { ->
@@ -62,35 +117,6 @@ dependencies {
62117
}
63118
}
64119

65-
def getAppResourcesPath() {
66-
def relativePathToApp = "app"
67-
def relativePathToAppResources
68-
def absolutePathToAppResources
69-
def projectRoot = "$rootDir/../../.."
70-
def nsConfigFile = file("$projectRoot/nsconfig.json")
71-
def nsConfig
72-
73-
if (nsConfigFile.exists()) {
74-
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
75-
}
76-
77-
if(nsConfig != null && nsConfig.appPath != null){
78-
relativePathToApp = nsConfig.appPath
79-
}
80-
81-
if(nsConfig != null && nsConfig.appResourcesPath != null ) {
82-
relativePathToAppResources = nsConfig.appResourcesPath
83-
} else {
84-
relativePathToAppResources = "$relativePathToApp/App_Resources"
85-
}
86-
87-
absolutePathToAppResources = java.nio.file.Paths.get(projectRoot).resolve(relativePathToAppResources).toAbsolutePath()
88-
89-
project.ext.appResourcesPath = absolutePathToAppResources
90-
91-
return absolutePathToAppResources
92-
}
93-
94120
def applyBeforePluginGradleConfiguration() {
95121
def appResourcesPath = getAppResourcesPath()
96122
def pathToBeforePluginGradle = "$appResourcesPath/Android/before-plugins.gradle"

0 commit comments

Comments
 (0)