【问题标题】:SBT: Append setting in sequence inside PlayKeys.devSettingsSBT:在 PlayKeys.devSettings 中按顺序附加设置
【发布时间】:2018-04-18 17:28:26
【问题描述】:

我在 Java 的 Play 框架中工作,我需要在开发过程中添加某些定制模块。 到目前为止,我通过添加具有以下内容的新 conf 文件来做到这一点:

include "application.conf"
play.modules.enabled += "DevModule"

并像这样运行 sbt:

sbt -Dconfig.file=conf/local.conf

this link 上,我发现可以使用 PlayKeys.devSettings 并覆盖您选择的播放设置。如果我可以在 build.sbt 中使用该语法和类似的东西会很好:

PlayKeys.devSettings := Seq("play.modules.enabled" -> "DevModule")

但是这个不起作用,因为我在运行时遇到了这个异常:

play.api.Configuration$$anon$1: Configuration error[hardcoded value: 
play.modules.enabled has type STRING rather than LIST]

我知道"DevModule" 需要插入到"play.modules.enabled" 的列表中,但我不知道如何在 sbt 中执行此操作,因为我不了解 Scala。

【问题讨论】:

    标签: scala playframework sbt


    【解决方案1】:

    PlayKeys.devSettings 期望提供Seq[(String, String)])。 试试这个表格,就像你在 conf 文件中写的一样:

    PlayKeys.devSettings :=  Seq(""""play.modules.enabled+="""" -> "DevModule")
    

    这是将设置应用于列表的方式。 您可以通过在控制器中的某处打印来调试配置内容,例如:

    //...other imports
    import com.typesafe.config.Config
    
    class ApplicationController @Inject()(
      config: Config
      //...
    ) extends MessagesAbstractController(cc) {
    
      def index() = Action{ implicit r =>
        println(config.getList("play.modules.enabled"))
        Ok(views.html.index())
      }
    }
    

    【讨论】:

    • build.sbt 现在已编译,但构建中不包含 DevModule。我认为,在 sbt 中,我需要获取名为 play.modules.enabled 的列表并附加字符串 DevModule"play.modules.enabled +=" 似乎什么也没做。例如。像这样的东西 PlayKeys.devSettings := Seq("play.server.http.port" -> "8080"),但 http.server.http.port 需要字符串。
    • 这很奇怪,我在自己的项目上尝试过,打印配置play.modules.enabled的内容。抱歉,这个愚蠢的问题,build.sbt 下方的某个地方是否还有另一个 PlayKeys.devSettings := 可能会覆盖此设置?
    • 我试图用给定的方法显示所有的配置值,但是play.modules.enabled里面没有我的DevModule。使用您建议的解决方案,我可以在 Configuration play.modules.enabled+= 中看到以下键,但这不是我需要的。如果我在 sbt 启动期间手动添加配置文件,DevModule 在配置中可见
    猜你喜欢
    • 2020-09-21
    • 2018-03-23
    • 1970-01-01
    • 2013-05-26
    • 2011-06-20
    • 1970-01-01
    • 2021-07-08
    • 2021-08-08
    • 2021-07-19
    相关资源
    最近更新 更多