Howto create .jar, including both sources (.java and .scala) and classes with sbt?

I would like sbt package or any option to create ".jar" from my project, which would also include sources (.java and .scala files).

This will be a combination of packageBin and packageSrc.

I did not do:

  • find any task that does this?
  • find a way to adapt the package task
  • and do not define a new task to achieve this goal.

Thanks for any hint.

+6
source share
2 answers

Looking at the documentation , you should probably add material to the mappings key in the packageBin . For me, it seems to work:

 mappings in (Compile, packageBin) ++= (mappings in (Compile, packageSrc)).value 
+2
source

Here's how to set up a standalone task to create 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 want, you can override package to use packageBinSrc :

 Keys.`package` := (packageBinSrc in Compile).value 
+2
source

Source: https://habr.com/ru/post/984308/


All Articles