How to optimize gradle build performance regarding build duration and RAM usage?

后端 未结 9 1387

I am currently switching from ant to gradle for my multi module web application and at the moment it seems that the current version of Gradle (M9) might be running up agains

9条回答
  •  抹茶落季
    2020-12-02 11:47

    If using the Gradle Wrapper you can set DEFAULT_JVM_OPTS in gradlew like this:

    DEFAULT_JVM_OPTS="-Xmx512m"
    

    Set it in a similar fashion in gradlew.bat if you're on Windows:

    set DEFAULT_JVM_OPTS=-Xmx512m
    

    The Gradle Wrapper task can also be modified to include this automatically. This is how the Gradle developers have solved it:

    wrapper {
        gradleVersion = '1.8'
    
        def jvmOpts = "-Xmx512m"
        inputs.property("jvmOpts", jvmOpts)
        doLast {
            def optsEnvVar = "DEFAULT_JVM_OPTS"
            scriptFile.write scriptFile.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"")
            batchScript.write batchScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
        }
    }
    

提交回复
热议问题