android - 如何在gradle中为任务设置绝对路径
问题描述
我有这样的基本任务
task copy-Library(type: Copy) {
from 'build/outputs/aar/app-debug_-debug.aar'
into "D:\\root\\path\\to\\directory\\Plugins\\Android"
rename { String fileName ->
fileName.replace("app-debug_-debug.aar", "myLibray-debug.aar")
}
}
它工作正常
但我想将路径"D:\\root\\path\\to\\directory\\Plugins\\Android"
放入某个变量中,以便我可以从其他任务中调用
into myPath
我猜我的 gradle 任务会以这样的方式结束
\\ set the path variable
how.do.I.set myPath = "D:\\root\\path\\to\\directory\\Plugins\\Android"
task copy-Library(type: Copy) {
from 'build/outputs/aar/app-debug_-debug.aar'
into myPath
rename { String fileName ->
fileName.replace("app-debug_-debug.aar", "myLibray-debug.aar")
}
}
这样我就可以添加另一个使用相同路径的任务?
task deleteLibrary(type: Delete){
delete fileTree(myPath) {
include '**/*.ext'
}
}
解决方案
我认为def
这就是你想要的:
def myPath = "D:\\root\\path\\to\\directory\\Plugins\\Android" //define variable myPath
task copy-Library(type: Copy) {
from 'build/outputs/aar/app-debug_-debug.aar'
into myPath //"$myPath" also should work
rename { String fileName ->
fileName.replace("app-debug_-debug.aar", "myLibray-debug.aar")
}
}
task deleteLibrary(type: Delete){
delete fileTree($myPath) {
include '**/*.ext'
}
}
推荐阅读
- angular - eslint 未检测到角度组件 html nx.dev 中缺少的属性或函数
- powershell - 如何在此 PowerShell 脚本中产生错误
- shopify - 如何在 shopify 中使用 graphiql api 获取页面或文章?
- javascript - asp.net 中的 jQuery 表单验证:在 depriated 输入时报告警告消息,同时在错误输入时保持错误
- python - 返回后功能未结束
- javascript - 使用绘制图像在画布中无法正确缩放图像
- sql - 根据排名(底部和顶部)创建组 (Redshift)
- javascript - 为什么谷歌图表为烛台图提供不同的输出?
- reactjs - 将函数作为 prop 传递,该函数返回一些 jsx 模板
- flutter - 有没有办法用 Flutter 制作鼻子建模应用程序