我想从URL下载zip文件(我的数据库)并将其提取到特定文件夹(例如资源)中。我想在我的项目构建sbt文件中执行此操作。 这样做的适当方法是什么? 我知道sbt.IO已经解压缩并下载了。我找不到一个使用下载的好例子(那些我发现不起作用)。 有什么sbt插件可以帮我吗?
我想从URL下载zip文件(我的数据库)并将其提取到特定文件夹(例如资源)中。我想在我的项目构建sbt文件中执行此操作。 这样做的适当方法是什么? 我知道sbt.IO已经解压缩并下载了。我找不到一个使用下载的好例子(那些我发现不起作用)。 有什么sbt插件可以帮我吗?
目前还不清楚你何时想要下载和提取,所以我打算用它来做 TaskKey
。这将创建一个可以从被调用的sbt控制台运行的任务 downloadFromZip
,它将下载sbt zip并将其解压缩到临时文件夹:
lazy val downloadFromZip = taskKey[Unit]("Download the sbt zip and extract it to ./temp")
downloadFromZip := {
IO.unzipURL(new URL("https://dl.bintray.com/sbt/native-packages/sbt/0.13.7/sbt-0.13.7.zip"), new File("temp"))
}
如果路径已存在,则可以将此任务修改为仅运行一次:
downloadFromZip := {
if(java.nio.file.Files.notExists(new File("temp").toPath())) {
println("Path does not exist, downloading...")
IO.unzipURL(new URL("https://dl.bintray.com/sbt/native-packages/sbt/0.13.7/sbt-0.13.7.zip"), new File("temp"))
} else {
println("Path exists, no need to download.")
}
}
要让它在编译时运行,请添加此行 build.sbt
(或项目设置 Build.scala
)。
compile in Compile <<= (compile in Compile).dependsOn(downloadFromZip)
目前还不清楚你何时想要下载和提取,所以我打算用它来做 TaskKey
。这将创建一个可以从被调用的sbt控制台运行的任务 downloadFromZip
,它将下载sbt zip并将其解压缩到临时文件夹:
lazy val downloadFromZip = taskKey[Unit]("Download the sbt zip and extract it to ./temp")
downloadFromZip := {
IO.unzipURL(new URL("https://dl.bintray.com/sbt/native-packages/sbt/0.13.7/sbt-0.13.7.zip"), new File("temp"))
}
如果路径已存在,则可以将此任务修改为仅运行一次:
downloadFromZip := {
if(java.nio.file.Files.notExists(new File("temp").toPath())) {
println("Path does not exist, downloading...")
IO.unzipURL(new URL("https://dl.bintray.com/sbt/native-packages/sbt/0.13.7/sbt-0.13.7.zip"), new File("temp"))
} else {
println("Path exists, no need to download.")
}
}
要让它在编译时运行,请添加此行 build.sbt
(或项目设置 Build.scala
)。
compile in Compile <<= (compile in Compile).dependsOn(downloadFromZip)