如何优化关于构建持续时间和 RAM 使用的 gradle 构建性能? [英] How to optimize gradle build performance regarding build duration and RAM usage?

查看:17
本文介绍了如何优化关于构建持续时间和 RAM 使用的 gradle 构建性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为我的多模块 Web 应用程序从 ant 切换到 gradle,目前看来当前版本的 Gradle (M9) 可能会遇到其限制.但也许(希望如此)这只是我对 Gradle 概念的理解不够好或不知道神奇的性能提升开关"的问题.我很乐意提供有关如何优化构建性能的任何提示.

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 against its limits. But maybe (hopefully) it is just a problem of me not understanding the concepts of Gradle good enough or not knowing the "magic performance boost switch". I'd be happy for any hint on how the build performance could be optimized.

问题:在显示第一个 compileJava 前几分钟过去了,即使源代码中没有任何变化,该进程也会运行至少 7 分钟,直到它在 中途崩溃:testClasses(在不同的子项目中)带有以下消息:

The problems: several minutes pass before the first compileJava is displayed, and even if nothing has changed in the sources, the process is running at least 7 minutes until it crashes halfway through :testClasses (at varying subprojects) with the following message:

* What went wrong:
Could not resolve all dependencies for configuration ':mysubproject_X:testRuntime'.
> Java heap space

该项目由大约 30 个(部分相互依赖的)子项目组成,它们的 build.gradle 或多或少相同,用于从每个子项目构建一个 jar 文件,例如

The project consists of about 30 (partly interdependent) subprojects, the build.gradle of them being more or less the same and are used to build a jar file from each subproject, e.g.

sourceSets {

    main {
        java {
            srcDirs 'src'
        }
    }
}

dependencies {

    compile project(':mysubproject_A')
    compile project(':mysubproject_B')
    compile project(':mysubproject_E')

    compile group: 'commons-lang', name: 'commons-lang', version: '2.2'

}

// copy all non-java files from src
copy {
    from sourceSets.main.java.srcDirs
    into "$buildDir/classes/main"
    exclude '**/*.java'
}

jar {
}

我试图通过将最大内存大小增加到 1024M 来解决堆空间问题,但没有帮助.我的主要 build.gradle 文件如下所示:

I tried to resolve the heap space problem by ramping up max memory size to 1024M, but it did not help. My main build.gradle file looks like this:

            sourceCompatibility = 1.6
            version = 0.5

            useFindBugs = false

            apply plugin: 'java'

            configurations {
            }

            repositories {
                mavenCentral()
                mavenRepo url:"http://repository.jboss.org/maven2", artifactUrls: ["https://repository.jboss.org/nexus/content/repositories/public","http://opensource.55minutes.com/maven-releases"]
            }


            dependencies {
            }

            buildscript {
                repositories {
                    mavenRepo url: 'http://gradle.artifactoryonline.com/gradle/plugins'
                    flatDir(dirs: "$projectDir/lib")
                }

                dependencies {
                    classpath "org.gradle.plugins:gradle-idea-plugin:0.3.1"
                }
            }

            subprojects {
                apply plugin: 'java'
                apply plugin: 'idea'

                repositories {
                    mavenCentral()
                    mavenRepo url:"http://repository.jboss.org/maven2", artifactUrls: ["https://repository.jboss.org/nexus/content/repositories/public","http://opensource.55minutes.com/maven-releases"]
                }

                dependencies {
                    testCompile 'junit:junit:4.8.2'
                }

                compileJava {
                    options.encoding = 'UTF-8'
                    options.fork (memoryMaximumSize: '1024m') 
                }

                javadoc {
                    options.encoding = 'UTF-8'
                }

                test {
                    testReportDir = file(rootProject.testReportDir)
                    forkEvery = 1
                    jvmArgs = ['-ea', '-Xmx1024m']
                }
            }


            dependsOnChildren()

            task wrapper(type: Wrapper) {
                gradleVersion = '1.0-milestone-9'
            }

推荐答案

您需要为 Gradle JVM 提供更多内存,而不是为编译任务/JVM.一种方法是通过 GRADLE_OPTS 环境变量 (GRADLE_OPTS=-Xmx512m).

You need to give more memory to the Gradle JVM, not to the compile task/JVM. One way to do so is via the GRADLE_OPTS environment variable (GRADLE_OPTS=-Xmx512m).

这篇关于如何优化关于构建持续时间和 RAM 使用的 gradle 构建性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆