sbt 0.10下收集依赖(将所有依赖jar放到target/scala-version/lib/) [英] Collecting dependencies under sbt 0.10 (putting all dependency jars to target/scala-version/lib/)
问题描述
我在 Scala 2.9.1 中使用 sbt 0.10.
I'm using sbt 0.10 with Scala 2.9.1.
但是我不想要一个大罐子.我只想要依赖 jars最终在 target/scala-2.9.1.final/lib 目录中.
However I don't want a one huge jar. I just want dependency jars ending up in target/scala-2.9.1.final/lib directory.
我不想要一个大罐子的原因,那个项目使用了很多libs,通常只有应用程序 .jar 更改.然而作为这是多语言项目,并非所有团队成员都有 scala 或 sbt,jars 只是提交给 git.拥有一个巨大的 dar 更新规则会增加回购规模.
The reason why I don't want a one huge jar, that project uses a lot of libs, and usually only the application .jar changes. However as this is multi-language project and not all team members have scala or sbt, jars are just commited to git. Having one huge dar updated regullary would inflate repo size.
如何复制这些依赖项?;)
How can I copy those dependencies? ;)
推荐答案
您没有指定要从中复制配置的 ivy 配置,但这里有一个完整的示例,它将复制所有您的托管依赖项到 target/
文件夹(scala 版本由 crossTarget 任务给出).只需复制它并将其放入文件 project/Build.scala
(或您想要的任何文件名):
You didn't specify the ivy configuration to copy the configurations from but here's a fully working example that will copy all your managed dependencies to the target/<scala version>/lib
folder (scala version is given by the crossTarget task). Just copy this and put it in the file project/Build.scala
(or whatever filename you want) :
import sbt._
import Keys._
object MyBuild extends Build {
lazy val copyDependencies = TaskKey[Unit]("copy-dependencies")
def copyDepTask = copyDependencies <<= (update, crossTarget, scalaVersion) map {
(updateReport, out, scalaVer) =>
updateReport.allFiles foreach { srcPath =>
val destPath = out / "lib" / srcPath.getName
IO.copyFile(srcPath, destPath, preserveLastModified=true)
}
}
lazy val root = Project(
"root",
file("."),
settings = Defaults.defaultSettings ++ Seq(
copyDepTask
)
)
}
如果需要特定配置,请替换
If you want a specific configuration, replace
updateReport.allFiles
by updateReport.select(configuration = Set("compile"))
或任何你想要的常春藤配置.
updateReport.allFiles
by updateReport.select(configuration = Set("compile"))
or whatever ivy configuration you want.
这篇关于sbt 0.10下收集依赖(将所有依赖jar放到target/scala-version/lib/)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!