You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2026/05/12 04:04:42 UTC
(cordova-android) branch feat/improved-gradle-build updated (1f455847 -> 03bd2f8d)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a change to branch feat/improved-gradle-build
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
discard 1f455847 feat: support adding project build script dependencies
new 03bd2f8d feat: support adding project build script dependencies
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (1f455847)
\
N -- N -- N refs/heads/feat/improved-gradle-build (03bd2f8d)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
templates/project/app/build.gradle | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
(cordova-android) 01/01: feat: support adding project build script dependencies
Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch feat/improved-gradle-build
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
commit 03bd2f8d3842cfcb33f397b468f33e1225d812ab
Author: Erisu <er...@apache.org>
AuthorDate: Tue May 12 13:02:42 2026 +0900
feat: support adding project build script dependencies
---
lib/AndroidProject.js | 14 ++++++++++++++
lib/builders/ProjectBuilder.js | 13 +++++++++++++
lib/pluginHandlers.js | 12 ++++++++++--
spec/unit/pluginHandlers/handlers.spec.js | 14 ++++++++++++++
templates/project/app/build.gradle | 3 +++
5 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/lib/AndroidProject.js b/lib/AndroidProject.js
index bc5f36c5..6665b3a2 100644
--- a/lib/AndroidProject.js
+++ b/lib/AndroidProject.js
@@ -124,6 +124,20 @@ class AndroidProject {
this._dirty = true;
}
+ addAppBuildScriptDependency (parentDir, value) {
+ const parentProjectFile = path.resolve(parentDir, 'project.properties');
+ const parentProperties = this._getPropertiesFile(parentProjectFile);
+ addToPropertyList(parentProperties, 'cordova.appbuildscript.dependency', value);
+ this._dirty = true;
+ }
+
+ removeAppBuildScriptDependency (parentDir, value) {
+ const parentProjectFile = path.resolve(parentDir, 'project.properties');
+ const parentProperties = this._getPropertiesFile(parentProjectFile);
+ removeFromPropertyList(parentProperties, 'cordova.appbuildscript.dependency', value);
+ this._dirty = true;
+ }
+
addSystemLibrary (parentDir, value) {
const parentProjectFile = path.resolve(parentDir, 'project.properties');
const parentProperties = this._getPropertiesFile(parentProjectFile);
diff --git a/lib/builders/ProjectBuilder.js b/lib/builders/ProjectBuilder.js
index 94658ee6..a0560cde 100644
--- a/lib/builders/ProjectBuilder.js
+++ b/lib/builders/ProjectBuilder.js
@@ -153,6 +153,7 @@ class ProjectBuilder {
return {
libs: findAllUniq(data, /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg),
gradleIncludes: findAllUniq(data, /^\s*cordova\.gradle\.include\.\d+=(.*)(?:\s|$)/mg),
+ appBuildScriptDependencies: findAllUniq(data, /^\s*cordova\.appbuildscript\.dependency\.\d+=((?!.*\().*)(?:\s|$)/mg),
systemLibs: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=((?!.*\().*)(?:\s|$)/mg),
bomPlatforms: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=platform\((?:'|")(.*)(?:'|")\)/mg)
};
@@ -280,6 +281,18 @@ class ProjectBuilder {
includeList += 'apply from: "../' + includePath + '"\n';
});
buildGradle = buildGradle.replace(/(PLUGIN GRADLE EXTENSIONS START)[\s\S]*(\/\/ PLUGIN GRADLE EXTENSIONS END)/, '$1\n' + includeList + '$2');
+
+ // Injecting buildscript dependencies
+ buildGradle = buildGradle.replace(
+ /^([\s\t]*)(APP-BUILDSCRIPT-DEPENDENCIES START)[\s\S]*(\/\/ APP-BUILDSCRIPT-DEPENDENCIES END)/m,
+ (match, indentLevel, startLine, _, endLine) => {
+ const buildScriptDeps = propertiesObj.appBuildScriptDependencies
+ .map(d => `${indentLevel}classpath "${d}"`)
+ .join('\n');
+ return `${indentLevel}${startLine}\n${buildScriptDeps}\n${indentLevel}${endLine}`;
+ }
+ );
+
// This needs to be stored in the app gradle, not the root grade
fs.writeFileSync(path.join(this.root, 'app', 'build.gradle'), buildGradle);
}
diff --git a/lib/pluginHandlers.js b/lib/pluginHandlers.js
index 14b0744f..eb3035cf 100644
--- a/lib/pluginHandlers.js
+++ b/lib/pluginHandlers.js
@@ -83,12 +83,16 @@ const handlers = {
copyNewFile(plugin.dir, src, project.projectDir, subRelativeDir, !!(options && options.link));
subDir = path.resolve(project.projectDir, subRelativeDir);
} else {
- obj.type = 'sys';
+ if (obj.type !== 'appBuildScriptDependency') {
+ obj.type = 'sys';
+ }
subDir = src;
}
if (obj.type === 'gradleReference') {
project.addGradleReference(parentDir, subDir);
+ } else if (obj.type === 'appBuildScriptDependency') {
+ project.addAppBuildScriptDependency(parentDir, subDir);
} else if (obj.type === 'sys') {
project.addSystemLibrary(parentDir, subDir);
} else {
@@ -113,12 +117,16 @@ const handlers = {
fs.rmdirSync(parDir);
}
} else {
- obj.type = 'sys';
+ if (obj.type !== 'appBuildScriptDependency') {
+ obj.type = 'sys';
+ }
subDir = src;
}
if (obj.type === 'gradleReference') {
project.removeGradleReference(parentDir, subDir);
+ } else if (obj.type === 'appBuildScriptDependency') {
+ project.removeAppBuildScriptDependency(parentDir, subDir);
} else if (obj.type === 'sys') {
project.removeSystemLibrary(parentDir, subDir);
} else {
diff --git a/spec/unit/pluginHandlers/handlers.spec.js b/spec/unit/pluginHandlers/handlers.spec.js
index b2145af8..2447fd57 100644
--- a/spec/unit/pluginHandlers/handlers.spec.js
+++ b/spec/unit/pluginHandlers/handlers.spec.js
@@ -197,6 +197,7 @@ describe('android project handler', function () {
spyOn(dummyProject, 'addSystemLibrary');
spyOn(dummyProject, 'addSubProject');
spyOn(dummyProject, 'addGradleReference');
+ spyOn(dummyProject, 'addAppBuildScriptDependency');
common.__set__('copyNewFile', copyNewFileSpy);
});
@@ -241,6 +242,12 @@ describe('android project handler', function () {
expect(copyNewFileSpy).toHaveBeenCalledWith(dummyPluginInfo.dir, framework.src, dummyProject.projectDir, someString, false);
expect(dummyProject.addGradleReference).toHaveBeenCalledWith(dummyProject.projectDir, someString);
});
+
+ it('Test#013 : should install app buildscript dependency using project.addAppBuildScriptDependency', () => {
+ const framework = { src: 'plugin-dependency', type: 'appBuildScriptDependency' };
+ android.framework.install(framework, dummyPluginInfo, dummyProject);
+ expect(dummyProject.addAppBuildScriptDependency).toHaveBeenCalledWith(dummyProject.projectDir, someString);
+ });
});
describe('of <js-module> elements', function () {
@@ -402,6 +409,7 @@ describe('android project handler', function () {
spyOn(dummyProject, 'removeSystemLibrary');
spyOn(dummyProject, 'removeSubProject');
spyOn(dummyProject, 'removeGradleReference');
+ spyOn(dummyProject, 'removeAppBuildScriptDependency');
});
it('Test#020 : should throw if framework doesn\'t have "src" attribute', function () {
@@ -433,6 +441,12 @@ describe('android project handler', function () {
expect(rmSyncSpy).toHaveBeenCalledWith(someString, { recursive: true, force: true });
expect(dummyProject.removeGradleReference).toHaveBeenCalledWith(dummyProject.projectDir, someString);
});
+
+ it('Test#025 : should uninstall app buildscript dependency using project.removeAppBuildScriptDependency', () => {
+ const framework = { src: 'plugin-dependency', type: 'appBuildScriptDependency' };
+ android.framework.uninstall(framework, dummyPluginInfo, dummyProject);
+ expect(dummyProject.removeAppBuildScriptDependency).toHaveBeenCalledWith(dummyProject.projectDir, someString);
+ });
});
describe('of <js-module> elements', function () {
diff --git a/templates/project/app/build.gradle b/templates/project/app/build.gradle
index 8bfae15e..393b9804 100644
--- a/templates/project/app/build.gradle
+++ b/templates/project/app/build.gradle
@@ -59,6 +59,9 @@ buildscript {
println "Adding classpath: ${gradlePluginGoogleServicesClassPath}"
classpath gradlePluginGoogleServicesClassPath
}
+
+ // APP-BUILDSCRIPT-DEPENDENCIES START
+ // APP-BUILDSCRIPT-DEPENDENCIES END
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org