diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildTask.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildTask.java index 44751d285074d..137fe96d0e738 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildTask.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildTask.java @@ -163,9 +163,7 @@ void generateBuild() { .collect(Collectors.joining("\n ", "\n ", ""))); } - WorkQueue workQueue = getWorkerExecutor() - .processIsolation(processWorkerSpec -> configureProcessWorkerSpec(processWorkerSpec, effectiveConfig, - extension().buildForkOptions)); + WorkQueue workQueue = workQueue(effectiveConfig, () -> extension().buildForkOptions); workQueue.submit(BuildWorker.class, params -> { params.getBuildSystemProperties().putAll(effectiveConfig.configMap()); diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateCode.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateCode.java index 0c8dd49a28754..5770278d3068f 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateCode.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateCode.java @@ -104,9 +104,7 @@ public void generateCode() { getLogger().debug("Will trigger preparing sources for source directory: {} buildDir: {}", sourcesDirectories, getProject().getBuildDir().getAbsolutePath()); - WorkQueue workQueue = getWorkerExecutor() - .processIsolation(processWorkerSpec -> configureProcessWorkerSpec(processWorkerSpec, effectiveConfig, - extension().codeGenForkOptions)); + WorkQueue workQueue = workQueue(effectiveConfig, () -> extension().codeGenForkOptions); workQueue.submit(CodeGenWorker.class, params -> { params.getBuildSystemProperties().putAll(effectiveConfig.configMap()); diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java index c255133f03c4b..7296c33730523 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java @@ -4,6 +4,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.function.Supplier; import javax.inject.Inject; @@ -11,6 +12,7 @@ import org.gradle.api.DefaultTask; import org.gradle.process.JavaForkOptions; import org.gradle.workers.ProcessWorkerSpec; +import org.gradle.workers.WorkQueue; import org.gradle.workers.WorkerExecutor; import io.quarkus.gradle.extension.QuarkusPluginExtension; @@ -35,12 +37,34 @@ QuarkusPluginExtension extension() { return extension; } - void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, EffectiveConfig effectiveConfig, + WorkQueue workQueue(EffectiveConfig effectiveConfig, Supplier>> forkOptionsActions) { + WorkerExecutor workerExecutor = getWorkerExecutor(); + + // Use process isolation by default, unless Gradle's started with its debugging system property or the + // system property `quarkus.gradle-worker.no-process is set to `true`. + if (Boolean.getBoolean("org.gradle.debug") || Boolean.getBoolean("quarkus.gradle-worker.no-process")) { + return workerExecutor.classLoaderIsolation(); + } + + return workerExecutor.processIsolation(processWorkerSpec -> configureProcessWorkerSpec(processWorkerSpec, + effectiveConfig, forkOptionsActions.get())); + } + + private void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, EffectiveConfig effectiveConfig, List> customizations) { JavaForkOptions forkOptions = processWorkerSpec.getForkOptions(); customizations.forEach(a -> a.execute(forkOptions)); + // Pass all system properties + System.getProperties().forEach((k, v) -> { + String key = k.toString(); + forkOptions.systemProperty(key, v); + }); + + // Pass all environment variables + forkOptions.environment(System.getenv()); + 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.