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

后端 未结 9 1389

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:56

    Put the following content to ~/.gradle as gradle.properties

    # Project-wide Gradle settings.
    # IDE (e.g. Android Studio) users:
    # Settings specified in this file will override any Gradle settings
    # configured through the IDE.
    # For more details on how to configure your build environment visit
    # http://www.gradle.org/docs/current/userguide/build_environment.html
    # The Gradle daemon aims to improve the startup and execution time of Gradle.
    # When set to true the Gradle daemon is to run the build.
    # TODO: disable daemon on CI, since builds should be clean and reliable on servers
    org.gradle.daemon=true
    # Specifies the JVM arguments used for the daemon process.
    # The setting is particularly useful for tweaking memory settings.
    # Default value: -Xmx10248m -XX:MaxPermSize=256m
    org.gradle.jvmargs=-Xmx6g -Xms4g -XX:MaxPermSize=8g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    # When configured, Gradle will run in incubating parallel mode.
    # This option should only be used with decoupled projects. More details, visit
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    org.gradle.parallel=true
    # Enables new incubating mode that makes Gradle selective when configuring projects.
    # Only relevant projects are configured which results in faster builds for large multi-projects.
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
    org.gradle.configureondemand=true
    
    0 讨论(0)
  • 2020-12-02 12:01

    None of the above answers worked for me, then I found this-

    My System Configuration-

    Windows x64 - JDK 32 bit - Cordova 5.4.1 - Ionic 1.7.12
    

    JVM options for running Gradle can be set via environment variables. You can use either GRADLE_OPTS or JAVA_OPTS, or both. JAVA_OPTS is by convention an environment variable shared by many Java applications. A typical use case would be to set the HTTP proxy in JAVA_OPTS and the memory options in GRADLE_OPTS. Those variables can also be set at the beginning of the gradle or gradlew script.

    I added the below mentioned two Environment Variables and solved this issue-

    Variable Name: GRADLE_OPTS
    Variable Value: -Xmx512m
    
    Variable Name: JAVA_OPTS
    Variable Value: -Xmx512m
    

    Hope this helps to guys like me.

    0 讨论(0)
  • 2020-12-02 12:02

    In the gradle.properties file add the following line :

    org.gradle.daemon=true

    This will boost the build - taken from

    https://www.timroes.de/2013/09/12/speed-up-gradle/

    0 讨论(0)
提交回复
热议问题