From 931428c3be399222857ba9b40aa14de73b875572 Mon Sep 17 00:00:00 2001 From: khalilou88 <32600911+khalilou88@users.noreply.github.com> Date: Fri, 6 Oct 2023 18:25:54 +0200 Subject: [PATCH] feat(executors): add NX_SKIP_GRADLE_WRAPPER environment variable (#503) Co-authored-by: khalilou88 --- packages/common/src/lib/command/index.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/common/src/lib/command/index.ts b/packages/common/src/lib/command/index.ts index 3efbc0d59..421134bc8 100644 --- a/packages/common/src/lib/command/index.ts +++ b/packages/common/src/lib/command/index.ts @@ -1,5 +1,7 @@ import { logger, workspaceRoot } from '@nx/devkit'; import { execSync } from 'child_process'; +import * as fs from 'fs'; +import * as path from 'path'; export async function waitForever() { return new Promise(() => { @@ -39,8 +41,20 @@ export function getPmdExecutable() { } export function getGradleExecutable() { - const isWin = process.platform === 'win32'; - let executable = isWin ? 'gradlew.bat' : './gradlew'; + let executable = ''; + + if (process.env['NX_SKIP_GRADLE_WRAPPER'] === 'true') { + executable = 'gradle'; + } else { + const isWrapperExists = isWrapperExistsFunction(); + + if (isWrapperExists) { + const isWin = process.platform === 'win32'; + executable = isWin ? 'gradlew.bat' : './gradlew'; + } else { + executable = 'gradle'; + } + } if (process.env['NX_GRADLE_CLI_OPTS']) { executable += ` ${process.env['NX_GRADLE_CLI_OPTS']}`; @@ -48,3 +62,8 @@ export function getGradleExecutable() { return executable; } + +function isWrapperExistsFunction() { + const gradlePath = path.join(workspaceRoot, 'gradlew'); + return fs.existsSync(gradlePath); +}