多模块 Scala 项目包含来自其他模块的 Conf 文件
Multi Module Scala Project Include Conf Files from other modules
我有一个多模块 Scala 应用程序,用于进行 ML 训练。我有一个核心模块,其中包含一些通用配置,我想将其添加到依赖于核心模块的其他模块中。
我所有的配置文件都位于资源文件夹中,我的项目结构如下所示:
core
src
main
resources
application.conf
mod1
src
main
resources
application.conf
mod2
src
main
resources
application.conf
所以我想在我的 mod1 和 mod2 模块的 application.conf 文件中,这是第一行:
include core/application.conf
这样我就可以从那里覆盖一些设置。我该怎么做呢?例如,这里是关于我如何定义模块 mod1 的 build.sbt 示例:
// Define Sub Modules and its settings
lazy val mod1 = (project in file(MODULE_NAME_CLEANSE)).dependsOn(core% "compile->compile;test->test", config)
.settings(
commonSettings,
enablingCoverageSettings,
dockerSettings(),
name := MODULE_1,
description := "Clean the incoming data for training purposes"
)
.enablePlugins(JavaAppPackaging, DockerPlugin)
假设您正在使用 Lighbend 的配置库。
一旦 built/deployed,您的 2 个模块将在其类路径中分别拥有来自核心模块的 application.conf
文件和来自所述模块的文件。两者都会加载,但您不能保证顺序。
推荐的方法是在核心模块中将其命名为 reference.conf
文件而不是 application.conf
因为这样你可以确定 reference.conf
的加载优先级低于 [=14] =].
参见https://github.com/lightbend/config#standard-behavior:
The convenience method ConfigFactory.load() loads the following (first-listed are higher priority):
- system properties
- application.conf (all resources on classpath with this name)
- application.json (all resources on classpath with this name)
- application.properties (all resources on classpath with this name)
- reference.conf (all resources on classpath with this name)
The idea is that libraries and frameworks should ship with a reference.conf in their jar. Applications should provide an application.conf
我有一个多模块 Scala 应用程序,用于进行 ML 训练。我有一个核心模块,其中包含一些通用配置,我想将其添加到依赖于核心模块的其他模块中。
我所有的配置文件都位于资源文件夹中,我的项目结构如下所示:
core
src
main
resources
application.conf
mod1
src
main
resources
application.conf
mod2
src
main
resources
application.conf
所以我想在我的 mod1 和 mod2 模块的 application.conf 文件中,这是第一行:
include core/application.conf
这样我就可以从那里覆盖一些设置。我该怎么做呢?例如,这里是关于我如何定义模块 mod1 的 build.sbt 示例:
// Define Sub Modules and its settings
lazy val mod1 = (project in file(MODULE_NAME_CLEANSE)).dependsOn(core% "compile->compile;test->test", config)
.settings(
commonSettings,
enablingCoverageSettings,
dockerSettings(),
name := MODULE_1,
description := "Clean the incoming data for training purposes"
)
.enablePlugins(JavaAppPackaging, DockerPlugin)
假设您正在使用 Lighbend 的配置库。
一旦 built/deployed,您的 2 个模块将在其类路径中分别拥有来自核心模块的 application.conf
文件和来自所述模块的文件。两者都会加载,但您不能保证顺序。
推荐的方法是在核心模块中将其命名为 reference.conf
文件而不是 application.conf
因为这样你可以确定 reference.conf
的加载优先级低于 [=14] =].
参见https://github.com/lightbend/config#standard-behavior:
The convenience method ConfigFactory.load() loads the following (first-listed are higher priority):
- system properties
- application.conf (all resources on classpath with this name)
- application.json (all resources on classpath with this name)
- application.properties (all resources on classpath with this name)
- reference.conf (all resources on classpath with this name)
The idea is that libraries and frameworks should ship with a reference.conf in their jar. Applications should provide an application.conf