在Android Studio的build.gradle
中,我可以编写一个包含用于CLI命令的常规代码的任务吗?我希望仅通过执行任务而不是每次都通过CLI运行它们来执行命令。就像我有一个要通过CLI执行的命令一样:
gradlew <task_name> -Dorg.ajoberstar.grgit.auth.hardcoded = true
在上面的命令中,我正在编写一个从bitbucket克隆存储库的任务,并在执行命令时在CLI中传递我的凭据。有什么办法可以在任务中编写此代码吗?
最佳答案
您可以在gradle脚本中的任何位置使用 System.setProperty()
。
因此,您只需在脚本的开头添加:
System.setProperty('org.ajoberstar.grgit.auth.hardcoded', 'true')
或更多groovier:
System.properties['org.ajoberstar.grgit.auth.hardcoded'] = true
但是最好将其直接放在任务中:
task someTask << {
System.properties['org.ajoberstar.grgit.auth.hardcoded'] = true
}
任务完成后,最好使用
System.clearProperty()
清除属性。
关于groovy - 在build.gradle中为CLI命令编写常规代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34758265/