6

I would like sbt package or any variant to produce a '.jar' from my project that would include also the sources ('.java' and '.scala' files).

This would be a mix of packageBin and packageSrc.

I did not:

  • find any task that would do this?
  • find how to adapt package task
  • nor define a new task of mine to achieve this

Thanks for any hint.

Tarod
  • 6,732
  • 5
  • 44
  • 50
ttamttam
  • 63
  • 5
  • possible duplicate of [Scala SBT: standalone jar](http://stackoverflow.com/questions/6026149/scala-sbt-standalone-jar) – Mogsdad Sep 01 '15 at 17:17

2 Answers2

2

Looking at the documentation, you should probably add stuff to the mappings key in the packageBin scope. The following seems to work for me:

mappings in (Compile, packageBin) ++= (mappings in (Compile, packageSrc)).value
0__
  • 66,707
  • 21
  • 171
  • 266
2

Here's how to setup a standalone task for creating an artifact with binaries and sources, leaving packageBin and packageSrc unaffected:

val packageBinSrc = taskKey[File]("Produces an artifact containing both binaries and sources.")

artifactClassifier in packageBinSrc := Some("binsrc")
inConfig(Compile) {
  import Defaults._
  packageTaskSettings(packageBinSrc, concatMappings(packageBinMappings, packageSrcMappings))
}

Optionally, if you fancy, you can redefine package to use packageBinSrc:

Keys.`package` := (packageBinSrc in Compile).value
Roberto Bonvallet
  • 31,943
  • 5
  • 40
  • 57
Dale Wijnand
  • 6,054
  • 5
  • 28
  • 55
  • Since there were two questions in one, both answers are of interest for me. Unfortunately, I have to mark one as "best". I chosed the shortest… Great thanks for those answers – ttamttam Mar 27 '15 at 15:10
  • I'd argue you're breaking the intent of `packageBin` by adding sources to it, but it is less setup code to be sure. – Dale Wijnand Mar 27 '15 at 15:18