Skip to content

Commit

Permalink
fix(gradle): fix gradlew exec path for root project
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Apr 30, 2024
1 parent 458f2cc commit 0761499
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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

0 comments on commit 0761499

Please sign in to comment.