runningcode / gradle-doctor

The right prescription for your Gradle build.
http://runningcode.github.io/gradle-doctor
Apache License 2.0
736 stars 48 forks source link

XX:+UseParallelGC to the org.gradle.jvmargs is not being picked up by Gradle Doctor #138

Closed ColtonIdle closed 3 years ago

ColtonIdle commented 3 years ago

I upgraded to the latest version of gradle doctor and was met with a new error:

Add -XX:+UseParallelGC to the org.gradle.jvmargs

This is what I currently have

org.gradle.jvmargs=-Xmx2048M -XX\:MaxPermSize\=4g -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8

I changed it to

org.gradle.jvmargs=-Xmx2048M -XX\:MaxPermSize\=4g -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8 -XX:+UseParallelGC

and it still doesn't work. I am a gradle noob, but this seems like the right spot? This is in the my root gradle.properties file.

Things I tried:

  1. I thought maybe since a gradle damon is running these changes wouldn't be picked up so I stopped all gradle daemons and ran it again
  2. I tried to edit something else in this file (android.enableJetifier) and set it to false, and my build failed... so this gradle.properties file is being picked up in general.
  3. I tried to print out the args that started the jvm and got this
 /Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/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.prefs/java.util.prefs=ALL-UNNAMED -Xmx8192m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp /Users/coltonidle/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/gradle-launcher-6.7.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.7

But that doesn't seem right because it reports Xmx as 8192 and I have it set to 2048. So I don't know what is printing out about the instance of java running. Also, I could have sworn I was using jdk 11 not 14. Switching to 11 didn't help things.

Hope to help any way I can.

runningcode commented 3 years ago

Thanks for filing. It does look like your build is not picking up the -XX:+UseParallelGC flag. If you are able to reproduce this in a small sample project that would help.

Can you try removing the \ in front of the colon for the :MaxPerSize? As well as the other \ in the file that aren't necessary?

Where is this gradle.properties file located?

ColtonIdle commented 3 years ago

I tried removing the slashes. Same issue.

I tried removing all properties and only putting in the GC flag and that didn't work either. Any chance you know if it's possible to somehow print out the args in gradle with some debug optino? I looked last night but couldn't find anything.

This file is located at the root of my project. I have two more gradle.properties files. 1. app module level and 2. a custom view module. I just tried deleting 1 and 2 and only leaving the root, but it still didn't work.

Minimal reproducible app?

File > New Project > Empty Activity Copy over the LEGACY setup from here: https://plugins.gradle.org/plugin/com.osacky.doctor Run build. Fails!

Hooray. It's not just my app!

Here is how the root level build.gradle looks

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.20"
    repositories {
        google()
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.0-alpha02"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.osacky.doctor:doctor-plugin:0.7.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

apply plugin: "com.osacky.doctor"

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
runningcode commented 3 years ago

Do you have anything in a gradle.properties file in your Gradle home? ~/.gradle/gradle.properties?

ColtonIdle commented 3 years ago

Apparently I do! org.gradle.jvmargs=-Xmx8192m

EDIT I don't remember creating that file... but I guess I did a while back. I'm assuming that it overriding everything else...

Jeez... if this is the cause of everything I will be relieved!

ColtonIdle commented 3 years ago

Yep! Deleted the file and everything is running smoothly now. @runningcode what would you say is the best place to put this stuff? I assume per project is best so that it shares between the team, but if my machine has more ram, where would I define that?

runningcode commented 3 years ago

You should choose the JVM args and heap size that allow the project to be built with no performance bottlenecks. You can check a build scan to see how full the heap size is during the build and how much time is spent garbage collecting. A build should not be spending a significant amount of time garbage collecting. Adding more memory to a build or project which does not have memory pressure does not improve build performance in any way. Therefore I would recommend setting these per project basis.

ColtonIdle commented 3 years ago

@runningcode thanks for the insight!

runningcode commented 3 years ago

Glad we got to the bottom of this! Closing this out.