[英]Not able to set command line arguments in gradle's JavaExec task
Not able to set command line arguments while configuring subprojects' task. 配置子项目的任务时无法设置命令行参数。
task doStuff {
def executable_task = project(':SubProject1').getTasksByName('run',true)
println executable_task.name
println executable_task.args
executable_task.args('xyz')
}
This error message is being showed: 显示此错误消息:
What went wrong: A problem occurred evaluating root project 'MainProject'.
出了什么问题:评估根项目“ MainProject”时发生问题。 No signature of method: java.util.HashSet.args() is applicable for argument types: (java.lang.String) values: [xyz] Possible solutions: any(), grep(), grep(), add(java.lang.Object), add(java.lang.Object), is(java.lang.Object)
没有方法签名:java.util.HashSet.args()适用于参数类型:(java.lang.String)值:[xyz]可能的解决方案:any(),grep(),grep(),add(java .lang.Object),add(java.lang.Object),is(java.lang.Object)
The method Project.getTasksByName() returns a Set
of Task
instances. 方法Project.getTasksByName()返回一
Set
Task
实例。 You will need to assign the field to each element in the Set
. 您需要将字段分配给
Set
每个元素。
task doStuff {
doLast {
Set<Task> executableTasks = project(':SubProject1').getTasksByName('run', true)
executableTasks.each {
it.args 'xyz'
}
}
}
BTW: I don't understand why you need to set arguments for a task in a different project. 顺便说一句:我不明白为什么您需要为另一个项目中的任务设置参数。 Couldn't you just set it in the subproject
:SubProject1
that defines the task? 您不能只在定义任务的子项目
:SubProject1
中进行设置吗? I'd actually set the task properties within :SubProject1
with a configuration rule: 我实际上是使用配置规则在
:SubProject1
设置任务属性:
tasks.withType(JavaExec).matching { it.name == 'run' }.each { it.args 'xyz' }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.