编译时如何将依赖jar解压到特定文件夹? [英] How to extract dependency jar to specific folder during compilation?

查看:28
本文介绍了编译时如何将依赖jar解压到特定文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些是我的项目的依赖项:

These are my project's dependencies:

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.

In com.company.common_2.11-2.3.3 there is a jar file common_2.11-2.3.3-adtnl.jar.

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

How can I during compilation process in build.sbt tell SBT to extract its contents to specific folder in my project?

推荐答案

build.sbt 中使用以下内容:

Use the following in 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.

It assumes that "common" is a unique part amongst all of your dependencies. You'd need to fix filter otherwise.

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

It also assumes that you don't really want the files at compile, but a bit later when package is called. You'd need to move the code between Def.task{...} to compile in Compile block like:

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]
})

这篇关于编译时如何将依赖jar解压到特定文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆