Skip to content

Commit

Permalink
Hack-ish fix for Windows, generating gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
snazy committed Mar 28, 2023
1 parent 6e76ed3 commit ee0f74f
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkus.gradle.tasks;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import javax.inject.Inject;
Expand All @@ -11,6 +14,7 @@
import org.gradle.workers.WorkerExecutor;

import io.quarkus.gradle.extension.QuarkusPluginExtension;
import io.quarkus.utilities.OS;

public abstract class QuarkusTask extends DefaultTask {

Expand All @@ -37,6 +41,21 @@ void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, EffectiveCo

customizations.forEach(a -> a.execute(forkOptions));

if (OS.determineOS() == OS.WINDOWS) {
// On Windows, gRPC code generation is sometimes(?) unable to find "java.exe". Feels (not proven) that
// the grpc code generation tool looks up "java.exe" instead of consulting the 'JAVA_HOME' environment.
// Might be, that Gradle's process isolation "loses" some information down to the worker process, so add
// both JAVA_HOME and updated PATH environment from the 'java' executable chosen by Gradle (could be from
// a different toolchain than the one running the build, in theory at least).
// Linux is fine though, so no need to add a hack for Linux.
String java = forkOptions.getExecutable();
Path javaBinPath = Paths.get(java).getParent().toAbsolutePath();
String javaBin = javaBinPath.toString();
String javaHome = javaBinPath.getParent().toString();
forkOptions.environment("JAVA_HOME", javaHome);
forkOptions.environment("PATH", javaBin + File.pathSeparator + System.getenv("PATH"));
}

// It's kind of a "very big hammer" here, but this way we ensure that all 'quarkus.*' properties from
// all configuration sources are (forcefully) used in the Quarkus build - even properties defined on the
// QuarkusPluginExtension.
Expand Down

0 comments on commit ee0f74f

Please sign in to comment.