| /* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| |
| // This script tries to guess sensible defaults for gradle parallelism |
| // and local machine's resources and save them under 'gradle.properties'. |
| |
| def hasDefaults = rootProject.file("gradle.properties").exists() |
| |
| configure(rootProject) { |
| // Add a task verifying that gradle process has access to JVM internals. |
| // this is occasionally needed for certain tasks. |
| task checkJdkInternalsExportedToGradle() { |
| doFirst { |
| def jdkCompilerModule = ModuleLayer.boot().findModule("jdk.compiler").orElseThrow() |
| def gradleModule = getClass().module |
| def internalsExported = [ |
| "com.sun.tools.javac.api", |
| "com.sun.tools.javac.file", |
| "com.sun.tools.javac.parser", |
| "com.sun.tools.javac.tree", |
| "com.sun.tools.javac.util" |
| ].stream() |
| .allMatch(pkg -> jdkCompilerModule.isExported(pkg, gradleModule)) |
| |
| if (!internalsExported) { |
| throw new GradleException( |
| "Certain gradle tasks and plugins require access to jdk.compiler" + |
| " internals, your gradle.properties might have just been generated or could be" + |
| " out of sync (see help/localSettings.txt)") |
| } |
| } |
| } |
| |
| task localSettings() { |
| doFirst { |
| // If we don't have the defaults yet, create them. |
| if (hasDefaults) { |
| logger.lifecycle("Local settings already exist, skipping generation.") |
| } else { |
| // Approximate a common-sense default for running gradle/tests with parallel |
| // workers: half the count of available cpus but not more than 12. |
| def cpus = Runtime.runtime.availableProcessors() |
| def maxWorkers = (int) Math.max(1d, Math.min(cpus * 0.5d, 12)) |
| def testsJvms = (int) Math.max(1d, Math.min(cpus * 0.5d, 12)) |
| |
| // Write the defaults for this machine. |
| rootProject.file("gradle.properties").write(""" |
| # These settings have been generated automatically on the first run. |
| # See gradlew :helpLocalSettings for more information. |
| systemProp.file.encoding=UTF-8 |
| |
| # Set up gradle JVM defaults. |
| # The heap seems huge but gradle runs out of memory on lower values (don't know why). |
| # |
| # We also open up internal compiler modules for spotless/ google java format. |
| org.gradle.jvmargs=-Xmx3g \\ |
| --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \\ |
| --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \\ |
| --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \\ |
| --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \\ |
| --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED |
| |
| # Run at normal priority, in parallel |
| org.gradle.parallel=true |
| org.gradle.priority=normal |
| |
| # This setting enables local task output caches. This will speed up |
| # your local builds in most cases but will also consume disk space in your |
| # gradle home. See SOLR-15603 for details. |
| # org.gradle.caching=true |
| |
| # Silence gradle warnings. We'll deal with them when we upgrade the wrapper. |
| org.gradle.warning.mode=none |
| |
| # You may disable the background daemon if it consumes too much memory. |
| org.gradle.daemon=true |
| # timeout after 15 mins of inactivity. |
| org.gradle.daemon.idletimeout=900000 |
| |
| # Maximum number of parallel gradle workers. |
| org.gradle.workers.max=${maxWorkers} |
| |
| # Maximum number of test JVMs forked per test task. |
| tests.jvms=${testsJvms} |
| |
| # Disable auto JVM provisioning (we don't use toolchains yet but want no surprises). |
| org.gradle.java.installations.auto-download=false |
| |
| # Set these to enable automatic JVM location discovery. |
| org.gradle.java.installations.fromEnv=JDK11,JDK12,JDK13,JDK14,JDK15,JDK16,JDK17 |
| org.gradle.java.installations.paths=(custom paths) |
| |
| """, "UTF-8") |
| |
| logger.log(LogLevel.WARN, "\nIMPORTANT. This is the first time you ran the build. " + |
| "I wrote some sane defaults (for this machine) to 'gradle.properties', " + |
| "they will be picked up on consecutive gradle invocations (not this one).\n\n" + |
| "Run gradlew :helpLocalSettings for more information.") |
| } |
| } |
| } |
| } |
| |
| if (!hasDefaults) { |
| // Make all tasks depend on local setup to make sure it'll run. |
| allprojects { |
| tasks.all { task -> |
| if (task != rootProject.localSettings) { |
| task.dependsOn rootProject.localSettings |
| } |
| } |
| } |
| } |