Playframework SBT使用SBT本机packager如何创建不同的生成文件?

Playframework SBT使用SBT本机packager如何创建不同的生成文件?,playframework,sbt,sbt-native-packager,Playframework,Sbt,Sbt Native Packager,我有一个Play 2.3应用程序,遵循我可以构建debian包的原则,当我想要构建这样的东西时,问题就来了: 我对dev、qa和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

我有一个Play 2.3应用程序,遵循我可以构建debian包的原则,当我想要构建这样的东西时,问题就来了:

我对dev、qa和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 ... 

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

使用多个.conf文件 这出戏用的是。为每个环境创建一个配置文件,例如

conf/
  reference.conf   # contains default settings
  dev.conf
  qa.conf
  prod.conf
现在如何定义哪一个被打包?嗯,有几个选择

将它们全部打包,并在启动时进行选择 打包所有内容并在启动时选择要使用的内容:

./bin/your-app -Dconfig.resource=conf/prod.conf
这是直截了当的,如果你能控制事情的开始方式,它就会起作用

打包它们并选择打包时间 您可以通过Universal中的
javaOptions在构建期间添加start命令。您可以使用a或a来执行此操作

复制并重命名特定的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
进行开发。

通常使用debian打包,您将使用一组参考配置安装软件包,并使用诸如或之类的工具来管理特定环境。感谢您的解释,很好,问题是我不想与包共享配置文件。我需要怎么做。你能告诉我怎么做吗?。所以在您的最后一个目的中,我必须构建三个包dev、prod、qa,每个包只有一个配置文件?