diff --git a/docs/src/docs/asciidoc/gradle-plugin.adoc b/docs/src/docs/asciidoc/gradle-plugin.adoc index fb8f569ba..919b64620 100644 --- a/docs/src/docs/asciidoc/gradle-plugin.adoc +++ b/docs/src/docs/asciidoc/gradle-plugin.adoc @@ -196,6 +196,14 @@ include::../snippets/gradle/kotlin/build.gradle.kts[tags=all-config-options] NOTE: For options that can be set using command-line, if both DSL and command-line options are present, command-line options take precedence. +[[max_parallel_builds]] +==== Max parallel builds + +When using Gradle parallel builds, the plugin will automatically limit the number of native images which can be built concurrently, in order to limit CPU and memory usage. +By default, it's limited to the number of CPU cores / 16, but you can change this limit either by setting the `org.graalvm.buildtools.max.parallel.builds` gradle property (e.g in your `gradle.properties` file) or by setting the `GRAALVM_BUILDTOOLS_MAX_PARALLEL_BUILDS` environment variable. + +[[configuration-advanced]] + [[long_classpath_and_fat_jar_support]] ==== Long classpath, @argument file and fat jar support diff --git a/docs/src/docs/asciidoc/index.adoc b/docs/src/docs/asciidoc/index.adoc index d5bc1b894..9790c7ea7 100644 --- a/docs/src/docs/asciidoc/index.adoc +++ b/docs/src/docs/asciidoc/index.adoc @@ -24,6 +24,7 @@ If you are using alternative build systems, see < { + + public static final String MAX_PARALLEL_SYSTEM_PROPERTY = "org.graalvm.buildtools.max.parallel.builds"; + public static final String MAX_PARALLEL_ENV_VAR = "GRAALVM_BUILDTOOLS_MAX_PARALLEL_BUILDS"; + public static Provider registerOn(Project project) { return project.getGradle() .getSharedServices() .registerIfAbsent("nativeImage", NativeImageService.class, spec -> { GraalVMLogger.newBuild(); - spec.getMaxParallelUsages().set(1 + Runtime.getRuntime().availableProcessors() / 16); + spec.getMaxParallelUsages().set(maxParallelUsagesOf(project.getProviders())); }); } + + private static Provider maxParallelUsagesOf(ProviderFactory providers) { + return providers.gradleProperty(MAX_PARALLEL_SYSTEM_PROPERTY) + .forUseAtConfigurationTime() + .orElse(providers.environmentVariable(MAX_PARALLEL_ENV_VAR).forUseAtConfigurationTime()) + .map(Integer::parseInt) + .orElse(1 + Runtime.getRuntime().availableProcessors() / 16); + } }