问题
These are my project's dependencies:
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaWs,
"com.company" % "common_2.11" % "2.3.3"
)
In com.company.common_2.11-2.3.3
there is a jar file common_2.11-2.3.3-adtnl.jar
.
How can I during compilation process in build.sbt
tell SBT to extract its contents to specific folder in my project?
回答1:
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
It assumes that "common"
is a unique part amongst all of your dependencies. You'd need to fix filter
otherwise.
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]
})
来源:https://stackoverflow.com/questions/26274698/how-to-extract-dependency-jar-to-specific-folder-during-compilation