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()
解决此错误?
> 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"
}
查看您的任务,我看到了为什么classpath设置失败的原因。您错过了=
。用等号表示您要设置JavaExec
类实例的属性。如果没有等号,那么您正在告诉groovy调用方法。由于不存在任何方法setClasspath
(classpath仅作为类的属性存在),因此该方法失败。
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)
方法的测试类
参考jvmArgs
中JavaExec
可以在这里找到:https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html#org.gradle.api.tasks.JavaExec:jvmArgs
编辑:没注意到您正在尝试传递JavaExec
对象。的实例JavaExec
作为arg传递到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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句