Skip to content

Commit 4e76ebc

Browse files
authoredMay 29, 2024··
fix: set GradleExecution jdk use java.import.gradle.java.home (#1491)
1 parent 44a4bfc commit 4e76ebc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed
 

‎extension/src/views/gradleDaemons/services/GradleLocalInstallation.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { GradleExecution } from "./GradleExecution";
22
import { execAsync } from "../../../util/execAsync";
3+
import { getConfigJavaImportGradleJavaHome } from "../../../util/config";
4+
import { logger } from "../../../logger";
5+
36
export class GradleLocalInstallation implements GradleExecution {
47
private gradleHomePath: string;
58

@@ -15,13 +18,17 @@ export class GradleLocalInstallation implements GradleExecution {
1518
const command = `${this.gradleHomePath} ${args.join(" ")}`;
1619

1720
try {
18-
const { stdout, stderr } = await execAsync(command);
21+
const jdkPath = getConfigJavaImportGradleJavaHome();
22+
const env = jdkPath ? { ...process.env, JAVA_HOME: jdkPath } : process.env;
23+
24+
const { stdout, stderr } = await execAsync(command, { env });
1925
if (stderr) {
20-
throw new Error(`Error running gradle: ${stderr}`);
26+
logger.error(stderr);
2127
}
2228
return stdout;
2329
} catch (error) {
24-
throw new Error(`Error running gradle: ${error.message}`);
30+
logger.error(error.message);
31+
throw new Error(`Error running gradle local installation: ${error.message}`);
2532
}
2633
}
2734
}

‎extension/src/views/gradleDaemons/services/GradleWrapper.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import * as fse from "fs-extra";
22
import { execAsync } from "../../../util/execAsync";
33
import { GradleExecution } from "./GradleExecution";
44
import * as path from "path";
5+
import { getConfigJavaImportGradleJavaHome } from "../../../util/config";
6+
import { logger } from "../../../logger";
57

68
export class GradleWrapper implements GradleExecution {
79
private gradleWrapperPath: string;
10+
811
constructor(private projectRoot: string) {
912
const wrapperName = process.platform === "win32" ? "gradlew.bat" : "gradlew";
1013
this.gradleWrapperPath = path.join(projectRoot, wrapperName);
@@ -17,12 +20,16 @@ export class GradleWrapper implements GradleExecution {
1720

1821
const command = `${this.gradleWrapperPath} ${args.join(" ")}`;
1922
try {
20-
const { stdout, stderr } = await execAsync(command, { cwd: this.projectRoot });
23+
const jdkPath = getConfigJavaImportGradleJavaHome();
24+
const env = jdkPath ? { ...process.env, JAVA_HOME: jdkPath } : process.env;
25+
26+
const { stdout, stderr } = await execAsync(command, { cwd: this.projectRoot, env });
2127
if (stderr) {
22-
throw new Error(`Error running gradle wrapper: ${stderr}`);
28+
logger.error(stderr);
2329
}
2430
return stdout;
2531
} catch (error) {
32+
logger.error(error.message);
2633
throw new Error(`Error running gradle wrapper: ${error.message}`);
2734
}
2835
}

0 commit comments

Comments
 (0)
Please sign in to comment.