Gradle JavaExec Task,如何使用allJvmArgs属性

时间:2014-10-23 10:02:02

标签: java groovy gradle

根据Java Exec allJvmArgs属性javadoc,allJvmArgs是

List<String> allJvmArgs

The full set of arguments to use to launch the JVM for the process. This includes arguments to define system properties, the minimum/maximum heap size, and the bootstrap classpath.

我试图使用此属性失败。以下是我的尝试。

示例Java代码。     // SRC /主/ JAVA / COM /实例

package com.examples;

public class AllJvmArgumentsInJavaExecBug {

    public static void main(String[] args) {
        System.out.println("Hello From Java");
    }

}


// File: build.gradle
apply plugin: 'java'

task(runJavaExecNormal, dependsOn: 'classes', type: JavaExec) {
    main = 'com.examples.AllJvmArgumentsInJavaExecBug'
    classpath = sourceSets.main.runtimeClasspath

}


task(runJavaExecArgumentSetExample1, dependsOn: 'classes', type: JavaExec) {
    main = 'com.examples.AllJvmArgumentsInJavaExecBug'
    classpath = sourceSets.main.runtimeClasspath
    allJvmArgs = [ '-Xms10240m', '-Xmx20280m']

}

task(runJavaExecArgumentSetExample2, dependsOn: 'classes', type: JavaExec) {
    main = 'com.examples.AllJvmArgumentsInJavaExecBug'
    classpath = sourceSets.main.runtimeClasspath

    List<String> argumentList = new ArrayList<String>();
    argumentList.add('-Xms10240m')
    argumentList.add('-Xmx20280m')
    allJvmArgs = argumentList
}

我收到以下错误。

P:\github\gradleJavaExecAllJvmArgs>gradle

FAILURE: Build failed with an exception.

* Where:
Build file 'P:\github\gradleJavaExecAllJvmArgs\build.gradle' line: 14

* What went wrong:
A problem occurred evaluating root project 'gradleJavaExecAllJvmArgs'.
> java.lang.UnsupportedOperationException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.733 secs

我无法使用此属性。 我可以使用maxHeapSize =&#34; 2g&#34;如question所指出的那样。 我想用它来设置最小堆大小。

以下是github project,它会重现这种情况。

1 个答案:

答案 0 :(得分:5)

来自org.gradle.process.internal.JavaExecHandleBuilder的来源包含:

public void setAllJvmArgs(Iterable<?> arguments) {
   throw new UnsupportedOperationException();
}

您应该可以使用jvmArgs代替allJvmArgs

相关问题