Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appending additional files to the fat JAR #227

Open
eed3si9n opened this issue Jan 10, 2017 · 2 comments
Open

Appending additional files to the fat JAR #227

eed3si9n opened this issue Jan 10, 2017 · 2 comments

Comments

@eed3si9n
Copy link
Member

There should be easier way to append to assembledMappings.
If there is one, document it.

@medale
Copy link

medale commented Mar 1, 2017

+1. assembledMappings is listed as one of the keys for the assembly task on the README.md but googling for it I only found older examples that did not compile in sbt 0.13.13. Any current examples? I am trying to add an application.conf file that was generated by the sbt editsource plugin (http://software.clapper.org/sbt-editsource/) to my fat jar. Any pointers in much appreciated!

@medale
Copy link

medale commented Mar 1, 2017

Example:
I was using the EditSource plugin to templatize version, project name (based on directory) and buildDate using the following settings where the template file is in module/templates/application.conf for each subproject (I had other template files and in this plugin only one targetDirectory can be specified - I did not want to put all the template output files in the fat jar):

lazy val editSourcePluginSettings = Seq(
  compile in Compile := ((compile in Compile) dependsOn (edit in EditSource)).value,
  flatten in EditSource := true,
  //use <module>/templates/application.conf
  sources in EditSource := Seq(
    baseDirectory.value / "templates/application.conf"
  ),
  targetDirectory in EditSource := baseDirectory.value / "target",
  variables in EditSource ++= Seq(
    ("version", version.value),
    ("projectDirName", baseDirectory.value.name),
    ("buildDate", dateFormat.format(new java.util.Date()))
  )
)

This put my application.conf under module/target/application.conf. I then used the following assembledMappings to get that application.conf into the root of my fat jar:

lazy val assemblyPluginSettings = Seq(  
...
  assembledMappings in assembly += {
    sbtassembly.MappingSet(None, Vector(
      (baseDirectory.value / "target" / "application.conf") -> "application.conf"
    ))
  }
...
)

In this case the file did not come from a jar file so the first argument in MappingSet is None, otherwise Some(new File(jarFilePath))? I have not tried that out but according to the MappingSet comments in AssemblyKeys.scala:

...
// Keep track of the source package of mappings that come from a jar, so we can
// sha1 the jar instead of the unpacked packages when determining whether to rebuild
case class MappingSet(sourcePackage : Option[File], mappings : Vector[(File, String)]) {
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants