我如何在IntegrationTest范围内配置FlyWay

时间:2016-01-27 22:47:13

标签: scala playframework sbt flyway

我正在尝试以不同方式配置flyway,因为它位于sbt中子项目内的IntegrationTest配置范围内:

// build.sbt

lazy val api = Project.project.in(file("api")).
  // ...
  settings(flywaySettings: _*).
  settings(
    // ...
    flywayUrl in IntegrationTest := "jdbc:postgresql://localhost:5432/mydb_test"
    flywayUser in IntegrationTest := "user"
    flywayPassword in IntegrationTest := "pw"
 )

但是当从sbt运行时,它仍然在寻找默认范围内的值:

$ sbt

> api/it:flywayUrl
[info] jdbc:postgresql://localhost:5432/mydb_test

> api/it:flywayUser
[info] user

> api/it:flywayPassword
[info] pw

> api/it:flywayMigrate
// ...
[info] Flyway 3.2.1 by Boxfuse
[trace] Stack trace suppressed: run last api/*:flywayMigrate for the full output.
[error] (api/*:flywayMigrate) org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!
[error] Total time: 3 s, completed 27-Jan-2016 1:33:08 PM

不确定我做错了什么......

1 个答案:

答案 0 :(得分:0)

看起来我需要使用inConfig

// build.sbt
lazy val api = Project.project.in(file("api")).

// copy the settings into the IntegrationTest Configuration
settings(inConfig(IntegrationTest)(flywaySettings): _*).
settings(
  // ...
  flywayUrl in IntegrationTest := "jdbc:postgresql://localhost:5432/mydb_test"
  flywayUser in IntegrationTest := "user"
  flywayPassword in IntegrationTest := "pw"
),

现在,命令api/it:flywayMigrate将从正确的范围获取值。