我正在尝试更新一个用groovy编写的maven插件,如果外部JVM可用,则使用它,否则,只使用默认JVM。我的代码更改如下所示:
def jvmExecutable = null;
if (someCondtion = true) {
jvmExecutable = "something"
}
def ant = new AntBuilder()
ant.java(fork: "${fork}", jvm: "${jvmExecutable}"....)
如果jvmExecutable为空,Groovy语言中有没有办法去掉jvm: "${jvmExecutable}"
指令?如果指定了jvm
,Groovy Ant任务希望在那里有一个可执行文件,但是如果我没有指定某些东西,我希望它使用它的默认值。
本质上,如果jvmExecutable != null
这样做
ant.java(fork: "${fork}", jvm: "${jvmExecutable}", ....)
或者如果jvmExecutable == null
这样做
ant.java(fork: "${fork}", ....)
谢谢!
发布于 2018-06-13 05:02:36
当您将命名参数传递给方法时,您实际上是在构建hashmap
所以这段代码
ant.echo(message:"hello", level:"error")
等于这一条
ant.echo( [message:"hello", level:"error"] )
最后,您希望在映射中只保留有效的值。如下所示:
ant.echo( [message:"hello", level:null].findAll{it.value!=null} )
https://stackoverflow.com/questions/50823380
复制相似问题