subodh
subodh

Reputation: 347

How can I include an additional file in the scripts folder that "sbt dist" generates inside target/universal?

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;} )

Upvotes: 0

Views: 768

Answers (1)

Muki
Muki

Reputation: 3641

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

Upvotes: 1

Related Questions