fix(gradle): fix gradle not working for spring (#23130)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Emily Xiong 2024-05-02 13:11:00 -04:00 committed by GitHub
parent e15720ba4f
commit 35f0618347
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 28 deletions

View File

@ -39,6 +39,10 @@ describe('Gradle', () => {
`list/build/libs/list.jar`,
`utilities/build/libs/utilities.jar`
);
expect(() => {
runCLI(`build ${gradleProjectName}`, { verbose: true });
}).not.toThrow();
});
it('should track dependencies for new app', () => {

View File

@ -82,7 +82,7 @@ describe('@nx/gradle/plugin', () => {
"targets": {
"test": {
"cache": false,
"command": "../gradlew test",
"command": "./gradlew proj:test",
"dependsOn": [
"classes",
],
@ -95,9 +95,6 @@ describe('@nx/gradle/plugin', () => {
"gradle",
],
},
"options": {
"cwd": "proj",
},
"outputs": undefined,
},
},
@ -147,7 +144,7 @@ describe('@nx/gradle/plugin', () => {
"targets": {
"test": {
"cache": false,
"command": "../../../gradlew test",
"command": "./gradlew proj:test",
"dependsOn": [
"classes",
],
@ -160,9 +157,6 @@ describe('@nx/gradle/plugin', () => {
"gradle",
],
},
"options": {
"cwd": "nested/nested/proj",
},
"outputs": undefined,
},
},

View File

@ -11,7 +11,7 @@ import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { getGradleRelativePath } from '../utils/exec-gradle';
import { getGradleExecFile } from '../utils/exec-gradle';
import { getGradleReport } from '../utils/get-gradle-report';
const cacheableTaskType = new Set(['Build', 'Verification']);
@ -126,10 +126,10 @@ export const createNodes: CreateNodes<GradlePluginOptions> = [
const { targets, targetGroups } = createGradleTargets(
tasks,
projectRoot,
options,
context,
outputDirs
outputDirs,
gradleProject
);
const project = {
name: projectName,
@ -155,10 +155,10 @@ export const createNodes: CreateNodes<GradlePluginOptions> = [
function createGradleTargets(
tasks: GradleTask[],
projectRoot: string,
options: GradlePluginOptions | undefined,
context: CreateNodesContext,
outputDirs: Map<string, string>
outputDirs: Map<string, string>,
gradleProject: string
): {
targetGroups: Record<string, string[]>;
targets: Record<string, TargetConfiguration>;
@ -172,12 +172,9 @@ function createGradleTargets(
const outputs = outputDirs.get(task.name);
targets[targetName] = {
command: `${getGradleRelativePath(
join(context.workspaceRoot, projectRoot)
)} ${task.name}`,
options: {
cwd: projectRoot,
},
command: `${getGradleExecFile()} ${
gradleProject ? gradleProject + ':' : ''
}${task.name}`,
cache: cacheableTaskType.has(task.type),
inputs: inputsMap[task.name],
outputs: outputs ? [outputs] : undefined,

View File

@ -29,15 +29,8 @@ 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 getGradleExecFile(): string {
return process.platform.startsWith('win') ? '.\\gradlew.bat' : './gradlew';
}
export function execGradleAsync(