如何在编译期间将依赖jar提取到特定文件夹?

时间:2014-10-09 09:18:40

标签: sbt

这些是我项目的依赖项:

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs,
  "com.company" % "common_2.11" % "2.3.3"
)

com.company.common_2.11-2.3.3中有一个jar文件common_2.11-2.3.3-adtnl.jar

如何在build.sbt编译过程中告诉SBT将其内容提取到项目中的特定文件夹?

1 个答案:

答案 0 :(得分:1)

build.sbt中使用以下内容:

def unpackjar(jar: File, to: File): File = {
  println(s"Processing $jar and saving to $to")
  IO.unzip(jar, to)
  jar
}

resourceGenerators in Compile += Def.task {
    val jar = (update in Compile).value
            .select(configurationFilter("compile"))
            .filter(_.name.contains("common"))
            .head
  val to = (target in Compile).value / "unjar"
  unpackjar(jar, to)
  Seq.empty[File]
}.taskValue

它假设"common"是所有依赖项中的唯一部分。否则,您需要修复filter

它还假设您并不真正想要compile处的文件,但稍后会调用package。您需要在Def.task{...}compile in Compile块之间移动代码,如:

compile in Compile <<= (compile in Compile).dependsOn(Def.task {
  val jar = (update in Compile).value
            .select(configurationFilter("compile"))
            .filter(_.name.contains("common"))
            .head
  val to = (target in Compile).value / "unjar"
  unpackjar(jar, to)
  Seq.empty[File]
})