0

Running sbt dist yields an output that looks like this:

    project_dir 
  | 
  |--- target/universal
          |
          |
          |
          | --- scripts
          |        |
          |        |--- blah.bat
          |        |--- blah (.sh file)
          |
          | --- blah-1.0-SNAPSHOT.zip (entire package zipped)

How do I go about copying a file so that it ends up in the target/universal/scripts folder? Any "mappings in Universal" tricks I tried resulted in the files I was copying ending up in the zip.

An example of what didn't work:

mappings in Universal ++=(baseDirectory.value / "scripts" * "*" get) map (x => x -> { x.setExecutable(true); baseDirectory.value.toString + "/test/" +  x.getName;} )
subodh
  • 337
  • 2
  • 6
  • 18

1 Answers1

1

If I understand your problem correctly you have two questions. First

How do I go about copying a file so that it ends up in the target/universal/scripts folder

This is most likely not what you want. The target/universal/scripts folder is nothing but a temporary folder were the scripts are generated before being zipped.

You can create files in arbitrary directories with a few lines of scala

lazy val writeSomeFiles = taskKey[Seq[File]]("Creates some files")
writeSomeFiles := {
  // `target/universal` folder
  val universalTarget = (target in Universal).value

  val sourceFiles = (baseDirectory.value ** AllPassFilter).get
  val destFiles = sourceFiles.map(file =>  universalTarget / file.getNamae)

  IO.copy(sourceFiles.zipWith(destFiles))

  destFiles
}

See: https://www.scala-sbt.org/1.x/api/sbt/io/AllPassFilter$.html See: https://www.scala-sbt.org/1.x/api/sbt/io/IO$.html

Second:

Any "mappings in Universal" tricks I tried resulted in the files I was copying ending up in the zip

That's exactly what the mappings in Universal are. The content of your created package (in this case as zip file). The dist (or universal:packageBin) task returns exactly one file, which is the created zip file.

If you plan to ship your package then this is the correct way to handle things.

hope that helps, Muki

Muki
  • 3,513
  • 3
  • 27
  • 50
  • Thanks Muki - the reason I am trying to copy an additional script into the scripts folder is because I need a script that will unzip the package, update symlinks and do some post deploy activities. I want this script to be under source control as well and also deployed as part of the project. – subodh Apr 02 '18 at 13:44