scala - Get resource file from dependency in sbt -
i have sbt-web project webjar , common jar dependencies. want resource file 1 of jar dependency , use in concatenation task. don't know how refer resource inside dependent jar in build.sbt.
i find solution this docs. main idea find right jar in classpath dependencies, unzip temprorary folder , need files. in case copy target directory , use in concatenation task.
i end code:
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 tmp directory val jarfile = classpathentry.data io.withtemporarydirectory { tmpdir => io.unzip(jarfile, tmpdir) // copy project's target directory // instead of copying can 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") }
this code should placed in task. example:
val copyresourcesfromjar = taskkey[unit]("copyresourcesfromjar", "copy resources jar dependencies") copyresourcesfromjar := { //your task code here } copyresourcesfromjar <<= copyresourcesfromjar dependson (dependencyclasspath in compile)
and don't forget add task dependcy build task. in case looks this:
concat <<= concat dependson copyresourcesfromjar
Comments
Post a Comment