我将如何在 IntegrationTest 范围内配置 FlyWay

How would I configure FlyWay in IntegrationTest scope

我试图在 sbt 中的子项目内的 IntegrationTest 配置范围内以不同方式配置 flyway:

// 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

不知道我做错了什么....

看来我需要使用 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 将从正确的范围获取值。