在Exec类型的gradle任务中,为什么commandLine和可执行文件的行为有所不同? [英] In gradle tasks of type Exec, why do commandLine and executable behave differently?

查看:1469
本文介绍了在Exec类型的gradle任务中,为什么commandLine和可执行文件的行为有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么类型Exec命令行和可执行文件的任务在继承环境变量方面表现不同吗?例如,我无法运行此任务,因为Gradle失败从我的环境中找到ruby:

pre $ task $ checkRubyVersionCommandLine(type:Exec){
commandLine'ruby -v'
}

然而,这工作正常:




args = ['-v']
}

什么是commandLine for,或者如何让它从它执行的shell中获取变量?为什么可执行文件正常工作?

解决方案

当使用commandLine时,需要将字符串拆分为空格,否则可执行文件变为' ruby -v',而不是'ruby'。

所以试试这个:

  task checkRubyVersionExecute(type:Exec){
commandLine'ruby','-v'
}

请参阅 here ,以查看Exec任务如何处理此操作。


Does anyone know why in tasks of type Exec commandline and executable behave differently in terms of inheriting environment vars?

For example, I cannot run this Task because Gradle fails to find ruby from my environment:

task checkRubyVersionCommandLine(type: Exec) {
       commandLine 'ruby -v'
}

Yet this works fine:

task checkRubyVersionExecute(type: Exec) {
    executable = 'ruby' 
    args = ['-v']
}

What is commandLine for, or how can I get it to pick up the variables from the shell it is executed from? Why does executable just work?

解决方案

When using the commandLine, you need to split the string on spaces, else the executable becomes 'ruby -v', instead of 'ruby'.

So try this instead:

task checkRubyVersionExecute(type: Exec) {
  commandLine 'ruby', '-v'
}

See the code here to see how the Exec task handles this.

这篇关于在Exec类型的gradle任务中,为什么commandLine和可执行文件的行为有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆