2016-03-08 43 views
0
def setSystemProperties(project) { 
    if (project.hasProperty('serverversion')) { 
     args(serverversion) 
    } 
    if (project.hasProperty('input_flavor')) { 
     systemProperties['input_flavor'] = input_flavor 
     print "gradle input_flavor" + input_flavor 
    } 
    jvmArgs = ["-Xms1024m", "-Xmx1024m"] 
    classpath sourceSets.main.runtimeClasspath 
} 



//warm up 

task BL_generate_parallel_warmup(type: JavaExec) { 
    setSystemProperties(project) 
    dependsOn resources_cleaner_bl 
    systemProperties['isDummyRun'] = 'true' 
    main = "astar.BlParallelGenerator" 
} 

我應該將什麼上下文傳遞給我的setSystemProperties()來修復此錯誤?如何將上下文傳遞給groovy中的自定義方法?

> No such property: jvmArgs for class: org.gradle.api.internal.project.DefaultProject_Decorated

> Could not find method classpath() for arguments [file collection] on root project 'RoutingRegression'.

代碼工作得很好,當這一切都在任務體:

//warm up 

task BL_generate_parallel_warmup(type: JavaExec) { 
     if (project.hasProperty('serverversion')) { 
     args(serverversion) 
    } 
    if (project.hasProperty('input_flavor')) { 
     systemProperties['input_flavor'] = input_flavor 
     print "gradle input_flavor" + input_flavor 
    } 
    jvmArgs = ["-Xms1024m", "-Xmx1024m"] 
    classpath sourceSets.main.runtimeClasspath 
    dependsOn resources_cleaner_bl 
    systemProperties['isDummyRun'] = 'true' 
    main = "astar.BlParallelGenerator" 
} 

回答

0

看着你的任務,我看到爲什麼在classpath設置失敗。你錯過了=。等號表示您設置JavaExec類實例的屬性。如果沒有等號,你就會告訴groovy調用一個方法。由於沒有方法存在setClasspath(類路徑僅作爲類的屬性存在),因此該方法失敗。

task runApp(type: JavaExec) { 
    classpath = sourceSets.main.runtimeClasspath 
    main = 'example.so.35869599.Main' 
    jvmArgs = ["-Xms1024m", "-Xmx1024m"] 
    // arguments to pass to the application 
    args 'blah!' 
} 

使用上述我能夠運行包含public static void main(String... args)方法

參考JavaExecjvmArgs一個測試類可以在這裏找到:​​

編輯:沒注意到你試圖通過周圍的JavaExec對象。 JavaExec的實例作爲參數傳遞給JavaExec配置閉包。我們可以用這樣的例子更清楚一點。

// here if we specify the type and name of the object passed to the closure 
// it becomes clearer where we can access the `jvmArgs` property. 
task runApp(type: JavaExec) { JavaExec exec -> 
    addArgsToJvm(exec) 
    classpath = sourceSets.main.runtimeClasspath 
    main = 'example.so.35869599.Main' 
    // arguments to pass to the application 
    args 'appArg1' 
} 

def addArgsToJvm(JavaExec exec) { 
    println "############################## caller passed: ${exec.getClass().getCanonicalName()}" 
    exec.jvmArgs = ["-Xms1024m", "-Xmx1024m"] 
} 

以上例子將顯示出該結果,在命令行:

############################## caller passed: org.gradle.api.tasks.JavaExec_Decorated 
相關問題