使用sbt-native-packager的SBT如何创建不同的构建文件? [英] SBT using sbt-native-packager how to create different build files?
问题描述
我有一个Play 2.3应用程序,根据文档,我可以构建一个debian软件包,当我要构建这样的东西时就会出现问题:
I have a Play 2.3 Application, following the docs I can build a debian package, the problem comes when I want to build things like this:
对于dev, qa and prod
,我有不同的配置,我想构建4个不同的程序包,一个包含代码,另一个包含配置.所以我将获得这4个软件包:
I have different configurations for dev, qa and prod
, and I want to build to 4 different packages, one that contains the code and the others that contains the configuration. so I will get this 4 packages:
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,我将需要其他一个作为依赖项,具体取决于机器.
but for installing app-version.deb I will need one of the others as a dependency depending on the machine.
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软件包配置应用程序不是一个好主意.对于播放应用程序,您还有其他更易于创建和维护的选项.
Configuring your application with additional debian packages is not a good idea in my experience. For a play application you have other options that are a lot easier to create and maintain.
Play使用类型安全配置库.为您的每个环境创建一个配置文件,例如
Play uses the Typesafe Config Library. Create a configuration file for each of your environments, e.g.
conf/
reference.conf # contains default settings
dev.conf
qa.conf
prod.conf
现在如何定义打包的那个?好吧,有一些选择.
Now how to define which one gets packaged? Well there are a few options.
打包所有文件并在启动时选择要使用的文件:
Package all and choose at startup time which to use:
./bin/your-app -Dconfig.resource=conf/prod.conf
这很简单,如果您可以控制事物的开始方式,则可以使用.
This is straight forward and works if you have control over how things get started.
您可以在构建期间通过javaOptions in Universal
添加启动命令.您可以使用命令来执行此操作别名或自定义任务
You can add the start command during build time via javaOptions in Universal
. You can do this either with a Command Alias or a custom task
基本上,您选择(例如,使用上述自定义任务)
配置包含为application.conf
.
Basically you choose (for example with a custom task as above) which
configuration to include as application.conf
.
mappings in Universal += {
val conf = (resourceDirectory in Compile).value / "reference.conf"
conf -> "conf/application.conf"
}
我建议您不要这样做,因为您目前不知道要使用哪个软件包.
I recommend against that as you have no idea which package you are using at the moment.
更新
配置/作用域更加复杂,并且有时会以意外的方式运行.一种简单的替代方法是使用子模块.
Configurations/Scopes are more complicated and behave sometimes in unexpected ways. The easy alternative is to use submodules.
your-app/
app
conf
..
dev/
qa/
prod/
您的build.sbt
随后将包含这样的内容
Your build.sbt
would then contain something like this
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
进行开发.
In the end you build with dev/debian:packageBin
for development.
这篇关于使用sbt-native-packager的SBT如何创建不同的构建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!