Creating two separate cans for sources and resources with a package in SBT?

Due to the large size of some resource files, I would like to sbt packagecreate 2 jar files at the same time, for example. project-0.0.1.jarfor classes and project-0.0.1-res.jarfor resources.

Is this doable?

[SOLUTION] based on the answer below, thanks @ gilad-hoch

1) unmanagedResources in Compile := Seq()

Now these are just classes in the jar by default.

2)

val packageRes = taskKey[File]("Produces a jar containing only the resources folder")
packageRes := {
  val jarFile = new File("target/scala-2.10/" + name.value + "_" + "2.10" + "-" + version.value + "-res.jar")
  sbt.IO.jar(files2TupleRec("", file("src/main/resources")), jarFile, new java.util.jar.Manifest)
  jarFile
}

def files2TupleRec(pathPrefix: String, dir: File): Seq[Tuple2[File, String]] = {
  sbt.IO.listFiles(dir) flatMap {
    f => {
      if (f.isFile) Seq((f, s"${pathPrefix}${f.getName}"))
      else files2TupleRec(s"${pathPrefix}${f.getName}/", f)
    }
  }
}

(packageBin in Compile) <<= (packageBin in Compile) dependsOn (packageRes)

Now, when I do the "sbt package", both the default jar and the resource container appear at the same time.

0
source share
1 answer

so as not to include resources in the main bank, you can simply add the following line:

unmanagedResources in Compile := Seq()

, . : sbt.IO jar . - :

def files2TupleRec(pathPrefix: String, dir: File): Seq[Tuple2[File,String]] = {
    sbt.IO.listFiles(dir) flatMap {
        f => {
            if(f.isFile) Seq((f,s"${pathPrefix}${f.getName}"))
            else files2TupleRec(s"${pathPrefix}${f.getName}/",f)
        }
    }
}
files2TupleRec("",file("path/to/resources/dir")) //usually src/main/resources

Path, sources: Traversable[(File, String)], jar . ...

0

All Articles