Skip to content

Instantly share code, notes, and snippets.

@jmfayard
Last active October 9, 2023 11:12
Show Gist options
  • Save jmfayard/6b489e1b20c646543a9e34304269a502 to your computer and use it in GitHub Desktop.
Save jmfayard/6b489e1b20c646543a9e34304269a502 to your computer and use it in GitHub Desktop.
Gradle Incompatible Daemons HOWTO

Add the printProperties task to your build.gradle

Run from both the command-line and intellij the gradle task printProperties

> Task :printProperties
Detecting what could cause incompatible gradle daemons
Run './gradlew printProperties' from the command-line and the same task Android studio
See https://docs.gradle.org/4.5/userguide/build_environment.html
See https://docs.gradle.org/4.5/userguide/gradle_daemon.html#daemon_faq

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
org.gradle.java.home=null
org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8 -Duser.country=DE
file.encoding=UTF-8
user.country=DE
user.language=en
java.io.tmpdir=/var/folders/4c/176bjfgn2fj9xp68ckjpz2940000gs/T/
user.variant=

If you have incompatible daemons, you should see something like this

$ ./gradlew --status
   PID STATUS   INFO
 42713 IDLE     4.5
 42195 IDLE     4.5

$  ps auxw | grep 'GradleDaemon'
jmfayard         42713   0.0  4.0 10257468 677436    ??  Ss   11:29AM   0:32.29 /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java -Xmx4g -Dfile.encoding=UTF-8 -Duser.country=DE -Duser.language=en -Duser.variant -cp /Users/jmfayard/.gradle/wrapper/dists/gradle-4.5-all/cg9lyzfg3iwv6fa00os9gcgj4/gradle-4.5/lib/gradle-launcher-4.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 4.5
jmfayard         42195   0.0  8.2 10387328 1372144   ??  Ss   11:08AM   2:56.25 /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/bin/java -Xmx4g -Dfile.encoding=UTF-8 -Duser.country=DE -Duser.language=en -Duser.variant -cp /Users/jmfayard/.gradle/wrapper/dists/gradle-4.5-all/cg9lyzfg3iwv6fa00os9gcgj4/gradle-4.5/lib/gradle-launcher-4.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 4.5

A big reason why the reasons are incompatible is that a different JDK is used.

This can be fixed by having the same value in the JAVA_HOME environment variable and in the Project Structure dialog

// $HOME/.bash_config
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"

image

Other incompatibilities can be fixed by updating gradle.properties until the task printProperties output the same value from both android studio and intellij.

task printProperties {
group = 'help'
doLast {
def properties = ['org.gradle.java.home', 'org.gradle.jvmargs']
def systemProperties = ['file.encoding', 'user.country', 'user.language', 'java.io.tmpdir', 'user.variant']
println("Detecting what could cause incompatible gradle daemons")
println("Run './gradlew printProperties' from the command-line and the same task Android studio")
println("See https://docs.gradle.org/4.5/userguide/build_environment.html")
println("See https://docs.gradle.org/4.5/userguide/gradle_daemon.html#daemon_faq")
println()
println "JAVA_HOME=" + System.getenv("JAVA_HOME")
properties.forEach { prop -> println(prop + "=" + project.findProperty(prop)) }
systemProperties.forEach { prop -> println(prop + "=" + System.properties[prop]) }
}
}
org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8 -Duser.country=DE
systemProp.file.encoding=UTF-8
systemProp.user.country=DE
systemProp.user.language=en
@cmargonis
Copy link

Many thanks for this invaluable task, it helped me debug the daemon differences! I've converted it to kotlin and also updated the links:

tasks.register("printProperties") {
    group = "help"
    doLast {
        val properties = listOf("org.gradle.java.home", "org.gradle.jvmargs")
        val systemProperties = listOf("file.encoding", "user.country", "user.language", "java.io.tmpdir", "user.variant")
        println("Detecting what could cause incompatible gradle daemons")
        println("Run './gradlew printProperties' from the command-line and the same task Android studio")
        println("See https://docs.gradle.org/7.5.1/userguide/build_environment.html")
        println("See https://docs.gradle.org/7.5.1/userguide/gradle_daemon.html#daemon_faq")
        println()
        println("JAVA_HOME=" + System.getenv("JAVA_HOME"))
        properties.forEach { prop -> println(prop + "=" + project.findProperty(prop)) }
        systemProperties.forEach { prop -> println(prop + "=" + System.getProperty(prop)) }
    }
}

@azabost
Copy link

azabost commented Jul 3, 2023

Thanks for the snippets. I'm not expecting any further advice but just for your information, running this task from the terminal and Android Studio gave me the same output - there were no differences. Yet, I still get Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment