我终于找到了这个文档的解决方案.主要思想是在类路径依赖项中找到正确的jar,将其解压缩到temprorary文件夹,并使用此文件执行所需操作.在我的情况下,我将其复制到我的目标目录并在连接任务中使用它.
我最终得到这个代码:
def copyResourceFromJar(classpathEntry: Attributed[File], jarName: String, resourceName: String) = {
classpathEntry.get(artifact.key) match {
case Some(entryArtifact) => {
// searching artifact
if (entryArtifact.name.startsWith(jarName)) {
// unpack artifact's jar to tmp directory
val jarFile = classpathEntry.data
IO.withTemporaryDirectory { tmpDir =>
IO.unzip(jarFile, tmpDir)
// copy to project's target directory
// Instead of copying you can do any other stuff here
IO.copyFile(
tmpDir / resourceName,
(WebKeys.webJarsDirectory in Assets).value / resourceName
)
}
}
}
case _ =>
}
}
for(entry <- (dependencyClasspath in Compile).value) yield {
copyResourceFromJar(entry, "firstJar", "firstFile.js")
copyResourceFromJar(entry, "secondJar", "some/path/secondFile.js")
}
Run Code Online (Sandbox Code Playgroud)
此代码应放在任务中.例如:
val copyResourcesFromJar = TaskKey[Unit]("copyResourcesFromJar", "Copy resources from jar dependencies")
copyResourcesFromJar := {
//your task code here
}
copyResourcesFromJar <<= copyResourcesFromJar dependsOn (dependencyClasspath in Compile)
Run Code Online (Sandbox Code Playgroud)
并且不要忘记将此任务添加为构建任务的依赖性.就我而言,它看起来像这样:
concat <<= concat dependsOn copyResourcesFromJar
Run Code Online (Sandbox Code Playgroud)