Skip to content

Commit

Permalink
feat(plugins): allow plugins to use kotlin files (#5555)
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug authored Aug 11, 2021
1 parent db53037 commit 37e2dbb
Showing 1 changed file with 56 additions and 30 deletions.
86 changes: 56 additions & 30 deletions vendor/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,72 @@
import groovy.json.JsonSlurper

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'


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
}

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 {
Expand All @@ -25,7 +81,6 @@ allprojects {
}
}

apply plugin: 'com.android.library'

def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 28 }
def computeBuildToolsVersion = { ->
Expand Down Expand Up @@ -62,35 +117,6 @@ dependencies {
}
}

def 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 applyBeforePluginGradleConfiguration() {
def appResourcesPath = getAppResourcesPath()
def pathToBeforePluginGradle = "$appResourcesPath/Android/before-plugins.gradle"
Expand Down

0 comments on commit 37e2dbb

Please sign in to comment.