Skip to content

Commit

Permalink
Gradle: ability to disable worker process isolation, pass all envs+sy…
Browse files Browse the repository at this point in the history
…s-props

* Gradle workers for Quarkus use _process_ isaolation by default. This
  can make debugging "tricky". This change changes this to _class
  loader_ isolation, if the `org.gradle.debug` or the
  `quarkus.gradle-worker.no-process` property is set to `true`.
* Also ensure that all environment variables and system properties are
  passed to the worker processes.

See also quarkusio#32465
  • Loading branch information
snazy committed Apr 11, 2023
1 parent e2bdd65 commit 3166309
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

workQueue.submit(BuildWorker.class, params -> {
params.getBuildSystemProperties().putAll(effectiveConfig.configMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

workQueue.submit(CodeGenWorker.class, params -> {
params.getBuildSystemProperties().putAll(effectiveConfig.configMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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;
Expand All @@ -35,12 +36,34 @@ QuarkusPluginExtension extension() {
return extension;
}

void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, EffectiveConfig effectiveConfig,
WorkQueue workQueue(EffectiveConfig effectiveConfig) {
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, extension().buildForkOptions));
}

private void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, EffectiveConfig effectiveConfig,
List<Action<? super JavaForkOptions>> 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.
Expand Down

0 comments on commit 3166309

Please sign in to comment.