diff --git a/packages/gradle/src/plugin/nodes.ts b/packages/gradle/src/plugin/nodes.ts index cdc8dbe7734f6..60092eb041c11 100644 --- a/packages/gradle/src/plugin/nodes.ts +++ b/packages/gradle/src/plugin/nodes.ts @@ -8,10 +8,10 @@ import { } from '@nx/devkit'; import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes'; import { existsSync } from 'node:fs'; -import { dirname, join, relative } from 'node:path'; +import { dirname, join } from 'node:path'; import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory'; -import { getGradleBinaryPath } from '../utils/exec-gradle'; +import { getGradleRelativePath } from '../utils/exec-gradle'; import { getGradleReport } from '../utils/get-gradle-report'; const cacheableTaskType = new Set(['Build', 'Verification']); @@ -171,12 +171,10 @@ function createGradleTargets( const targetName = options?.[`${task.name}TargetName`] ?? task.name; const outputs = outputDirs.get(task.name); - const path = relative( - join(context.workspaceRoot, projectRoot), - getGradleBinaryPath() - ); targets[targetName] = { - command: `${path} ${task.name}`, + command: `${getGradleRelativePath( + join(context.workspaceRoot, projectRoot) + )} ${task.name}`, options: { cwd: projectRoot, }, diff --git a/packages/gradle/src/utils/exec-gradle.ts b/packages/gradle/src/utils/exec-gradle.ts index 572e4dd3990a7..1ba0bddf43882 100644 --- a/packages/gradle/src/utils/exec-gradle.ts +++ b/packages/gradle/src/utils/exec-gradle.ts @@ -6,7 +6,7 @@ import { execFileSync, } from 'node:child_process'; import { existsSync } from 'node:fs'; -import { join } from 'node:path'; +import { join, relative } from 'node:path'; export function execGradle( args: string[], @@ -29,6 +29,17 @@ export function getGradleBinaryPath(): string { return gradleBinaryPath; } +export function getGradleRelativePath(path: string): string { + const gradleBinaryPath = getGradleBinaryPath(); + let relativePath = relative(path, gradleBinaryPath); + if (relativePath.startsWith('gradlew')) { + relativePath = process.platform.startsWith('win') + ? `.\\${relativePath}` + : `./${relativePath}`; + } + return relativePath; +} + export function execGradleAsync( args: ReadonlyArray, execOptions?: ExecFileOptions