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:
Thanks for any hint.
When you uses Simple Build Tool Command 'sbt package', it creates a jar file that includes the class files from your source code and also the content from your src/main/resources folder. Your project dependencies (JAR files in your project's lib folder or managed dependencies declared in build. sbt).
A JAR file created by SBT can be run by the Scala interpreter, but not the Java interpreter. This is because class files in the JAR file created by sbt package have dependencies on Scala class files (Scala libraries), which aren't included in the JAR file SBT generates.
This is part of SBT which play uses as a build tool. Specifically this is an import statement. The percent symbol % is a actually a method used to build dependencies. The double percent sign %% injects the current Scala version - this allows you to get the correct library for the version of scala you are running.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With