Intellij idea 如何在groovy中将上下文传递给自定义的方法?
我应该向我的Intellij idea 如何在groovy中将上下文传递给自定义的方法?,intellij-idea,gradle,groovy,Intellij Idea,Gradle,Groovy,我应该向我的setSystemProperties()传递什么上下文来修复此错误 >没有这样的属性:类的jvmArgs:org.gradle.api.internal.project.DefaultProject\u 或 >在根项目“RoutingRegression”上找不到参数[文件集合]的方法classpath()。 当代码都在任务体中时,它工作得很好: def setSystemProperties(project) { if (project.hasProperty('serv
setSystemProperties()
传递什么上下文来修复此错误
>没有这样的属性:类的jvmArgs:org.gradle.api.internal.project.DefaultProject\u
或
>在根项目“RoutingRegression”上找不到参数[文件集合]的方法classpath()。
当代码都在任务体中时,它工作得很好:
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"
}
通过查看您的任务,我了解了类路径设置失败的原因。您缺少
=
。使用等号表示设置JavaExec
类实例的属性。如果没有等号,那么您就告诉groovy调用一个方法。由于不存在方法setClasspath
(classpath仅作为类的属性存在),因此该方法失败
//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"
}
使用上面的代码,我能够运行一个包含公共静态voidmain(String…args)
方法的测试类
在JavaExec
中可以找到对jvmArgs
的引用:
编辑:没有注意到您试图传递JavaExec
对象。JavaExec
的实例作为参数传递给JavaExec
配置闭包。我们可以用这样一个例子来说明这一点
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'example.so.35869599.Main'
jvmArgs = ["-Xms1024m", "-Xmx1024m"]
// arguments to pass to the application
args 'blah!'
}
上面的示例将在命令行中显示此结果:
// 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