为什么Universal中的映射对tarball中包含的内容没有影响?

时间:2014-08-09 14:34:23

标签: sbt sbt-native-packager

build.sbt的摘要如下所示:

import com.github.bigtoast.sbtliquibase.LiquibasePlugin
import S3._
import com.typesafe.sbt.SbtNativePackager._
import com.typesafe.sbt.SbtNativePackager.Universal
import com.typesafe.sbt.packager.Keys._
import Path.flat

mappings in Universal ++= {
  ((baseDirectory.value / "src/main/migrations" * "*").get map { f => f -> (f.name) })
}

当我运行universal:packageZipTarball时,我希望src/main/migrations中的文件出现在最终的tarball中。他们没有。

我看到的是:

a database2-0.34.0
a database2-0.34.0/lib
a database2-0.34.0/lib/com.trailhunger.database2-0.34.0.jar
a database2-0.34.0/lib/org.postgresql.postgresql-9.3-1101-jdbc4.jar
a database2-0.34.0/lib/org.scala-lang.scala-library-2.10.3.jar

我构建的另一个项目中的代码非常相似。

1 个答案:

答案 0 :(得分:2)

tl; dr 您的构建对我来说很好。

这里有完整的build.sbt来重现您的问题:

packageArchetype.java_application

mappings in Universal ++= {
  ((sourceDirectory in Compile).value / "migrations" * "*").get.map { f => 
    f -> (f.name)
  }
}

要记住的要点是在构建中自己设置密钥之前放置packageArchetype.java_application,因为顺序很重要。

除了排序之外,sourceDirectory in Compile还有一个小变化,它为我提供了正确的src/main目录,而不是自己连接路径。

> show sourceDirectory
[info] /Users/jacek/sandbox/sbt-native-packager-playground/src
> show compile:sourceDirectory
[info] /Users/jacek/sandbox/sbt-native-packager-playground/src/main

<强>项目/ build.properties

sbt.version=0.13.6-M1

<强>项目/ SBT-天然-packager.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4")

src/main/migrations下我有一个文件 - migration1.txt - 会被添加到最终的tarball中。

> universal:packageZipTarball
[info] Wrote /Users/jacek/sandbox/sbt-native-packager-playground/target/scala-2.10/sbt-native-packager-playground_2.10-0.1-SNAPSHOT.pom
a sbt-native-packager-playground-0.1-SNAPSHOT
a sbt-native-packager-playground-0.1-SNAPSHOT/lib
a sbt-native-packager-playground-0.1-SNAPSHOT/migration1.txt
a sbt-native-packager-playground-0.1-SNAPSHOT/lib/default.sbt-native-packager-playground-0.1-SNAPSHOT.jar
a sbt-native-packager-playground-0.1-SNAPSHOT/lib/org.scala-lang.scala-library-2.10.4.jar
[success] Total time: 0 s, completed Aug 9, 2014 10:17:37 PM

这是universal:mappings的值,供参考:

> show universal:mappings
[info] Wrote /Users/jacek/sandbox/sbt-native-packager-playground/target/scala-2.10/sbt-native-packager-playground_2.10-0.1-SNAPSHOT.pom
[info] ArrayBuffer((/Users/jacek/sandbox/sbt-native-packager-playground/target/scala-2.10/sbt-native-packager-playground_2.10-0.1-SNAPSHOT.jar,lib/default.sbt-native-packager-playground-0.1-SNAPSHOT.jar), (/Users/jacek/.sbt/boot/scala-2.10.4/lib/scala-library.jar,lib/org.scala-lang.scala-library-2.10.4.jar), (/Users/jacek/sandbox/sbt-native-packager-playground/src/main/migrations/migration1.txt,migration1.txt))
[success] Total time: 0 s, completed Aug 9, 2014 10:16:27 PM