From 20ca9f13c11e5b53ea58ed26c361ffdd96e47983 Mon Sep 17 00:00:00 2001 From: Norman Breau Date: Thu, 9 May 2024 12:55:04 -0300 Subject: [PATCH] fix(windows): Gradle paths --- lib/builders/ProjectBuilder.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/builders/ProjectBuilder.js b/lib/builders/ProjectBuilder.js index 271e71401..7e75d1f40 100644 --- a/lib/builders/ProjectBuilder.js +++ b/lib/builders/ProjectBuilder.js @@ -26,7 +26,7 @@ const events = require('cordova-common').events; const CordovaError = require('cordova-common').CordovaError; const check_reqs = require('../check_reqs'); const PackageType = require('../PackageType'); -const { compareByAll } = require('../utils'); +const { compareByAll, isWindows } = require('../utils'); const { createEditor } = require('properties-parser'); const CordovaGradleConfigParserFactory = require('../config/CordovaGradleConfigParserFactory'); @@ -117,6 +117,16 @@ class ProjectBuilder { return args; } + getGradleWrapperPath () { + let wrapper = path.join(this.root, 'gradlew'); + + if (isWindows()) { + wrapper += '.bat'; + } + + return wrapper; + } + /** * Installs/updates the gradle wrapper * @param {string} gradleVersion The gradle version to install. Ignored if CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL environment variable is defined @@ -127,7 +137,7 @@ class ProjectBuilder { throw new CordovaError(`Cannot install Gradle ${gradleVersion}. Minimum Required is ${MIN_GRADLE_REQUIRED}.`); } - const wrapper = path.join(this.root, 'gradlew'); + const wrapper = this.getGradleWrapperPath(); if (process.env.CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL) { events.emit('verbose', `Overriding Gradle Version via CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL (${process.env.CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL})`); await execa(wrapper, ['-p', this.root, 'wrapper', '--gradle-distribution-url', process.env.CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL, '--validate-url'], { stdio: 'inherit' }); @@ -315,7 +325,7 @@ class ProjectBuilder { * Returns a promise. */ async build (opts) { - const wrapper = path.join(this.root, 'gradlew'); + const wrapper = this.getGradleWrapperPath(); const args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts); events.emit('verbose', `Running Gradle Build: ${wrapper} ${args.join(' ')}`); @@ -336,7 +346,7 @@ class ProjectBuilder { } clean (opts) { - const wrapper = path.join(this.root, 'gradlew'); + const wrapper = this.getGradleWrapperPath(); const args = this.getArgs('clean', opts); return execa(wrapper, args, { stdio: 'inherit', cwd: path.resolve(this.root) }) .then(() => {