Skip to content

Commit

Permalink
feat: include-settings.gradle plugin (#5693)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed authored Oct 18, 2022
1 parent aa3de73 commit 6155ff7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
);
const allGradleTemplateFiles = path.join(gradleTemplatePath, "*");
const buildGradlePath = path.join(pluginTempDir, "build.gradle");

const settingsGradlePath = path.join(pluginTempDir, "settings.gradle");

this.$fs.copyFile(allGradleTemplateFiles, pluginTempDir);
this.addCompileDependencies(platformsAndroidDirPath, buildGradlePath);
const runtimeGradleVersions = await this.getRuntimeGradleVersions(
Expand All @@ -423,6 +424,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
runtimeGradleVersions.gradleAndroidPluginVersion
);
this.replaceFileContent(buildGradlePath, "{{pluginName}}", pluginName);
this.replaceFileContent(settingsGradlePath, "{{pluginName}}", pluginName);
}

private async getRuntimeGradleVersions(
Expand Down
24 changes: 24 additions & 0 deletions vendor/gradle-plugin/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
import groovy.json.JsonSlurper

def USER_PROJECT_ROOT = "$rootDir/../../../"
def PLATFORMS_ANDROID = "platforms/android"
def PLUGIN_NAME = "{{pluginName}}"

def dependenciesJson = file("${USER_PROJECT_ROOT}/${PLATFORMS_ANDROID}/dependencies.json")
def appDependencies = new JsonSlurper().parseText(dependenciesJson.text)
def pluginData = appDependencies.find { it.name == PLUGIN_NAME }
def nativescriptDependencies = appDependencies.findAll{pluginData.name == it.name}

def getDepPlatformDir = { dep ->
file("$USER_PROJECT_ROOT/$PLATFORMS_ANDROID/${dep.directory}/$PLATFORMS_ANDROID")
}

def applyIncludeSettingsGradlePlugin = {
nativescriptDependencies.each { dep ->
def includeSettingsGradlePath = "${getDepPlatformDir(dep)}/include-settings.gradle"
if (file(includeSettingsGradlePath).exists()) {
apply from: includeSettingsGradlePath
}
}
}

applyIncludeSettingsGradlePlugin()

0 comments on commit 6155ff7

Please sign in to comment.