We’ve been getting this message in our builds rece...
# gradle
a
We’ve been getting this message in our builds recently and can’t figure out why:
Copy code
To honour the JVM settings for this build a single-use Daemon process will be forked.
We’ve set up these environment variables:
Copy code
JAVA_OPTS: '-Xmx3g -Xms1g'
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx3g -Xms1g" -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy="in-process"'
Are we missing any options? Is there a way to get Gradle to give us more detailed error messages on exactly which settings are different? We’re using
./gradlew
to start up the process, and noticed that it specifies defaults in
DEFAULT_JVM_OPTS
. Are those possibly getting in the way?
t
This is related to
-Dorg.gradle.daemon=false
a
Yup, we’re intentionally disabling the daemon in CI so we can use a single JVM process, but Gradle is still spinning up a single-use daemon
We’re trying to follow the info here:
If you deactivate the Gradle Daemon and the client VM has the same settings as required for the build VM, the client VM will run the build directly. Otherwise the client VM will fork a new VM to run the actual build in order to honor the different settings.
We thought we configured the settings the same for everything, but Gradle seems to be forking its own VM anyway.
c
there’s a few other key settings; file.encoding comes to mind (will try and track down the reference list).
Copy code
-Dfile.encoding=UTF-8
This lists the properties that define Gradle daemon compatibility
a
Awesome thanks — I’ll take a look We’re not manually overriding those flags anywhere, but I wouldn’t be surprised if some line deep in
./gradlew
is setting something
c
file.encoding is platform dependent, will differ on Windows, good bet to start there. We
We always force that to utf-8 for consistency.
running with --debug shows the options used to start the daemon, perhaps some info there.
Copy code
➜  core-plugin git:(main) ./gradlew --no-daemon --debug | more
2022-05-04T14:27:25.349-0700 [INFO] [org.gradle.internal.nativeintegration.services.NativeServices] Initialized native services in: /Users/chrislee/.gradle/native
2022-05-04T14:27:25.366-0700 [INFO] [org.gradle.internal.nativeintegration.services.NativeServices] Initialized jansi services in: /Users/chrislee/.gradle/native
2022-05-04T14:27:25.382-0700 [LIFECYCLE] [org.gradle.launcher.cli.DebugLoggerWarningAction]
#############################################################################
   WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

   Debug level logging will leak security sensitive information!

   <https://docs.gradle.org/7.4.2/userguide/logging.html#sec:debug_security>
#############################################################################

2022-05-04T14:27:25.433-0700 [LIFECYCLE] [org.gradle.launcher.daemon.client.SingleUseDaemonClient] To honour the JVM settings for this build a single-use Daemon process will be forked. See <https://docs.gradle.org/7.4.2/userguide/gradle_daemon.html#sec:disabling_the_daemon>.
2022-05-04T14:27:25.447-0700 [DEBUG] [org.gradle.launcher.daemon.client.DefaultDaemonStarter] Using daemon args: [/Users/chrislee/Library/Java/JavaVirtualMachines/corretto-17.0.3/Contents/Home/bin/java, --add-opens, java.base/java.util=ALL-UNNAMED, --add-opens, java.base/java.lang=ALL-UNNAMED, --add-opens, java.base/java.lang.invoke=ALL-UNNAMED, --add-opens, java.base/java.util=ALL-UNNAMED, --add-opens, java.prefs/java.util.prefs=ALL-UNNAMED, --add-opens, java.prefs/java.util.prefs=ALL-UNNAMED, --add-opens, java.base/java.nio.charset=ALL-UNNAMED, --add-opens, java.base/java.net=ALL-UNNAMED, --add-opens, java.base/java.util.concurrent.atomic=ALL-UNNAMED, -XX:MaxMetaspaceSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xms256m, -Xmx512m, -Dfile.encoding=UTF-8, -Duser.country=CA, -Duser.language=en, -Duser.variant, -cp, /Users/chrislee/.gradle/wrapper/dists/cloudshift-gradle-7.4.2-1.0.6/2h7o13bsllwb0ye1wg54wgu74/cloudshift-gradle-7.4.2-1.0.6/lib/gradle-launcher-7.4.2.jar]
2022-05-04T14:27:25.449-0700 [DEBUG] [org.gradle.launcher.daemon.client.DefaultDaemonStarter] Starting daemon process: workingDir = /Users/chrislee/.gradle/daemon/7.4.2, daemonArgs: [/Users/chrislee/Library/Java/JavaVirtualMachines/corretto-17.0.3/Contents/Home/bin/java, --add-opens, java.base/java.util=ALL-UNNAMED, --add-opens, java.base/java.lang=ALL-UNNAMED, --add-opens, java.base/java.lang.invoke=ALL-UNNAMED, --add-opens, java.base/java.util=ALL-UNNAMED, --add-opens, java.prefs/java.util.prefs=ALL-UNNAMED, --add-opens, java.prefs/java.util.prefs=ALL-UNNAMED, --add-opens, java.base/java.nio.charset=ALL-UNNAMED, --add-opens, java.base/java.net=ALL-UNNAMED, --add-opens, java.base/java.util.concurrent.atomic=ALL-UNNAMED, -XX:MaxMetaspaceSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xms256m, -Xmx512m, -Dfile.encoding=UTF-8, -Duser.country=CA, -Duser.language=en, -Duser.variant, -cp, /Users/chrislee/.gradle/wrapper/dists/cloudshift-gradle-7.4.2-1.0.6/2h7o13bsllwb0ye1wg54wgu74/cloudshift-gradle-7.4.2-1.0.6/lib/gradle-launcher-7.4.2.jar, org.gradle.launcher.daemon.bootstrap.GradleDaemon, 7.4.2]
2022-05-04T14:27:25.455-0700 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'Gradle build daemon'. Working directory: /Users/chrislee/.gradle/daemon/7.4.2 Command: /Users/chrislee/Library/Java/JavaVirtualMachines/corretto-17.0.3/Contents/Home/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=CA -Duser.language=en -Duser.variant -cp /Users/chrislee/.gradle/wrapper/dists/cloudshift-gradle-7.4.2-1.0.6/2h7o13bsllwb0ye1wg54wgu74/cloudshift-gradle-7.4.2-1.0.6/lib/gradle-launcher-7.4.2.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.4.2
a
Nice I’ll try that out. Is there a way to get both the daemon args and the VM args so it’s easy to compare?
c
Not that I’m aware of. Have code (below) to dump out what Gradle is executing, but that is after it’s decided how to execute it.
Copy code
private fun setupDebug() {
        // <https://docs.gradle.org/7.1/userguide/gradle_daemon.html#daemon_faq>
        val immutableSysProps = setOf(
            "file.encoding",
            "user.language",
            "user.country",
            "user.variant",
            "java.io.tmpdir",
            "javax.net.ssl.keyStore",
            "javax.net.ssl.keyStorePassword",
            "javax.net.ssl.keyStoreType",
            "javax.net.ssl.trustStore",
            "javax.net.ssl.trustStorePassword",
            "javax.net.ssl.trustStoreType",
            "com.sun.management.jmxremote",
            "java.version"
        )
        val excludedProps = setOf(
            "gradle.wrapperPassword",
            "gradle.wrapperUser"
        )

        System.getProperties()
            .filter { (k, _) ->
                k.toString() in immutableSysProps || k.toString().toLowerCase().contains("gradle")
            }.filter { (k, _) ->
                k.toString() !in excludedProps
            }
            .forEach { (k, v) ->
                logger.debug("DEBUG: System property: $k = $v")
            }
        System.getenv().filter { (k, _) -> k.toLowerCase().contains("gradle") }.forEach { (k, v) ->
            logger.debug("DEBUG: Environment variable: $k = $v")
        }
    }
This is from the Gradle internals that compares the build environments to decide whether to use a single use daemon or not:
Copy code
public boolean configureForBuild(DaemonParameters requiredBuildParameters) {
        boolean javaHomeMatch = getJvm().equals(requiredBuildParameters.getEffectiveJvm());

        boolean immutableJvmArgsMatch = true;
        if (requiredBuildParameters.hasUserDefinedImmutableJvmArgs()) {
            immutableJvmArgsMatch = getJvmOptions().getAllImmutableJvmArgs().equals(requiredBuildParameters.getEffectiveSingleUseJvmArgs());
        }
        if (javaHomeMatch && immutableJvmArgsMatch && !isLowDefaultMemory(requiredBuildParameters)) {
            // Set the system properties and use this process
            Properties properties = new Properties();
            properties.putAll(requiredBuildParameters.getEffectiveSystemProperties());
            System.setProperties(properties);
            return true;
        }
        return false;
    }