fix(gradle): fix gradlew exec path for root project (#23094)
This commit is contained in:
parent
c8d44b0355
commit
30a3875a0d
@ -8,10 +8,10 @@ import {
|
|||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
|
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
|
||||||
import { existsSync } from 'node:fs';
|
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 { 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';
|
import { getGradleReport } from '../utils/get-gradle-report';
|
||||||
|
|
||||||
const cacheableTaskType = new Set(['Build', 'Verification']);
|
const cacheableTaskType = new Set(['Build', 'Verification']);
|
||||||
@ -171,12 +171,10 @@ function createGradleTargets(
|
|||||||
const targetName = options?.[`${task.name}TargetName`] ?? task.name;
|
const targetName = options?.[`${task.name}TargetName`] ?? task.name;
|
||||||
|
|
||||||
const outputs = outputDirs.get(task.name);
|
const outputs = outputDirs.get(task.name);
|
||||||
const path = relative(
|
|
||||||
join(context.workspaceRoot, projectRoot),
|
|
||||||
getGradleBinaryPath()
|
|
||||||
);
|
|
||||||
targets[targetName] = {
|
targets[targetName] = {
|
||||||
command: `${path} ${task.name}`,
|
command: `${getGradleRelativePath(
|
||||||
|
join(context.workspaceRoot, projectRoot)
|
||||||
|
)} ${task.name}`,
|
||||||
options: {
|
options: {
|
||||||
cwd: projectRoot,
|
cwd: projectRoot,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
execFileSync,
|
execFileSync,
|
||||||
} from 'node:child_process';
|
} from 'node:child_process';
|
||||||
import { existsSync } from 'node:fs';
|
import { existsSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join, relative } from 'node:path';
|
||||||
|
|
||||||
export function execGradle(
|
export function execGradle(
|
||||||
args: string[],
|
args: string[],
|
||||||
@ -29,6 +29,17 @@ export function getGradleBinaryPath(): string {
|
|||||||
return gradleBinaryPath;
|
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(
|
export function execGradleAsync(
|
||||||
args: ReadonlyArray<string>,
|
args: ReadonlyArray<string>,
|
||||||
execOptions?: ExecFileOptions
|
execOptions?: ExecFileOptions
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user