我目前正在将我的多模块Web应用从Ant迁移到Gradle,目前看来当前版本的Gradle(M9)可能已经到达其极限。但也许(希望)只是我不太理解Gradle的概念或不知道“魔法性能提升开关”的问题。我很乐意听取有关如何优化构建性能的任何提示。
问题:在显示第一个compileJava
之前要等待几分钟,即使在源中没有更改,进程也至少运行了7分钟,直到在:testClasses
(在不同的子项目中)崩溃并显示以下消息:
* What went wrong:
Could not resolve all dependencies for configuration ':mysubproject_X:testRuntime'.
> Java heap space
该项目由大约30个(部分相互依赖的)子项目组成,它们的build.gradle文件大多数相同,用于从每个子项目构建一个jar文件,例如:
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文件如下:
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'
}