Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gradle): fix gradlew exec path for root project #23094

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions packages/gradle/src/plugin/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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,
},
Expand Down
13 changes: 12 additions & 1 deletion packages/gradle/src/utils/exec-gradle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand All @@ -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<string>,
execOptions?: ExecFileOptions
Expand Down