java - Exec 任务的动态 gradle 命令失败
问题描述
我正在尝试将 Lambda zip 文件发布到 s3- s3://my-aws-lambda/<projectName>/[release|SNAPSHOT]/
。下面定义的任务publishToS3
失败并显示消息
Caused by: java.io.FileNotFoundException: /Users/me/my-lambda/build/distributions
当我跑步时
./gradlew clean build -x test -x release
感谢任何帮助。谢谢。
task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtimeClasspath
}
}
task publishToS3(type: Exec, dependsOn: buildZip) {
onlyIf { file("${project.buildDir}/distributions").exist() }
def artifacts = new FileNameByRegexFinder().getFileNames("${project.buildDir}/distributions", /.*\.zip/)
assert artifacts.size() == 1
def isSnapShot = artifacts[0].endsWith('-SNAPSHOT.zip')
def releaseCmd = ("aws s3 cp " +
"${artifacts[0]} " +
"s3://my-aws-lambdas/${project.name}/${isSnapShot ? 'SNAPSHOT' : 'release'}/ ").trim().tokenize(' ') as List
workingDir "${project.buildDir}/distributions"
commandLine releaseCmd
}
build.dependsOn buildZip
解决方案
如果您在 UNIX 环境中,您可以使用该find
命令来搜索文件并使用它的输出。
task scanFiles() {
def a= "find ${project.buildDir} -name *.zip".execute().text
String[] files=a.split('\n')
if(files.length == 1){
println("We'v got a file :"+a)
}
else if(files.length ==0){
println("We've not no files ")
}
else{
println("We've got multiple files\n"+a)
}
}
推荐阅读
- spring - 从 @value 访问从后端 java 对象加载的属性
- visual-studio-code - VSCode ANTLR4 插件:将调用图导出为 JSON?
- ssl - 无法使用 https 访问网站
- c++ - 编译 C++ Boost iostream 库时出错
- python - sysconfig.get_config_var("VERSION") 过期
- hyperledger-fabric - 超级账本结构链码 | Abstore Go 应用程序构建授予权限问题
- bash - VLC 流脚本链失败
- javascript - FullCalendar V4 中的 refetchEvents 等价物
- django - 如何修复 DateRangeFilter 以使日期小部件正确显示
- java - 根据 recyclerview 中的最后一次聊天显示用户