SBT使用sbt-native-packager如何创建不同的构建文件?

时间:2015-06-16 15:14:07

标签: playframework sbt sbt-native-packager

我有一个Play 2.3应用程序,在docs之后我可以构建一个debian软件包,当我想构建这样的东西时问题出现了:

我有dev, qa and prod的不同配置,我想构建4个不同的包,一个包含代码,另一个包含配置。所以我会得到这4个包裹:

app-version.deb [this contains the code]
app-config-dev-version.deb [this contains the dev configuration]
app-config-qa-version.deb [this contains the qa configuration]
app-config-prod-version.deb‏ [this contains the prod configuration]

但是对于安装app-version.deb,我需要其中一个作为依赖项,具体取决于计算机。

machine-dev: app-version.deb and app-config-dev-version.deb
machine-qa:  app-version.deb and app-config-qa-version.deb
and so on ... 

1 个答案:

答案 0 :(得分:0)

根据我的经验,使用额外的debian软件包配置您的应用程序并不是一个好主意。对于播放应用程序,您可以使用其他更易于创建和维护的选项。

使用多个.conf文件

Play使用Typesafe Config Library。为每个环境创建配置文件,例如

conf/
  reference.conf   # contains default settings
  dev.conf
  qa.conf
  prod.conf

现在如何定义哪一个被打包?那么有几个选择。

将它们打包并在启动时选择

打包所有并在启动时选择使用:

./bin/your-app -Dconfig.resource=conf/prod.conf

这是直截了当的,如果您可以控制事情的开始,它就会起作用。

将它们打包并选择包​​时间

您可以在构建期间通过javaOptions in Universal添加启动命令。您可以使用Command Aliascustom task

执行此操作

复制并重命名特定的conf

基本上你选择(例如使用上面的自定义任务) 配置为application.conf

mappings in Universal += {
  val conf = (resourceDirectory in Compile).value / "reference.conf"
  conf -> "conf/application.conf"
}

我建议不要这样做,因为你不知道你目前使用的是哪个包。

<强>更新

使用子模块

配置/范围更复杂,有时会以意想不到的方式表现。简单的替代方法是使用子模块。

your-app/
  app
  conf
  ..
dev/
qa/
prod/

您的build.sbt将包含类似

的内容
lazy val app = project
  .in(file("your-app"))
  .enabledPlugins(PlayScala)
  .settings(
     // your settings
  )

lazy val dev = project
  .in(file("dev"))
  // this one is tricky. 
  // Maybe it works when using the PlayScala Plugin
  .enabledPlugins(PlayScala)
  .settings(
    // if you only use the JavaServerAppPackaging plugin 
    // you will need to specifiy a mainclass
    //mainClass in Compile := Some("")
)

// ... rest the same way

最后,您使用dev/debian:packageBin进行构建以进行开发。

相关问题