Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document SBT custom configuration usage #1275

sourcesmith opened this issue Apr 8, 2016 · 7 comments

Document SBT custom configuration usage #1275

sourcesmith opened this issue Apr 8, 2016 · 7 comments


Copy link

@sourcesmith sourcesmith commented Apr 8, 2016

Observed with Flyway-sbt 4.0.

A custom configuration with flyway specific settings was created, including url, username and password. This was verified by show and inspect

> show local-deployment:flywayUrl
[info] jdbc:postgresql://localhost:5432/db

> inspect local-deployment:flywayUrl
[info] Delegates:
[info]  local-deployment:flywayUrl
[info]  deployment-internal:flywayUrl
[info]  runtime:flywayUrl
[info]  compile:flywayUrl
[info]  *:flywayUrl
[info]  {.}/local-deployment:flywayUrl
[info]  {.}/deployment-internal:flywayUrl
[info]  {.}/runtime:flywayUrl
[info]  {.}/compile:flywayUrl
[info]  {.}/*:flywayUrl
[info]  */local-deployment:flywayUrl
[info]  */deployment-internal:flywayUrl
[info]  */runtime:flywayUrl
[info]  */compile:flywayUrl
[info]  */*:flywayUrl

When a flyway task is executed scoped to a custom configuration rather than the task being actioned, the following error was displayed:

> local-deployment:flywayInfo
[info] Flyway 4.0 by Boxfuse
[trace] Stack trace suppressed: run last *:flywayInfo for the full output.
[error] (*:flywayInfo) org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!
[error] Total time: 1 s, completed 08-Apr-2016 12:01:51

From the sbt plugins best practise, hence the expectation the task should have actioned correctly:

"a plugin should strive to support multiple configurations, including those created by the build user. Some tasks that are tied to a particular configuration can be re-used in other configurations. While you may not see the need immediately in your plugin, some project may and will ask you for the flexibility."

@sourcesmith sourcesmith changed the title sbt task does not use configuration settngs sbt task does not use configuration settings Apr 8, 2016
Copy link

@axelfontaine axelfontaine commented Apr 8, 2016

@cdedie Thoughts?

Copy link

@sourcesmith sourcesmith commented Apr 11, 2016

Having looked into the implementation of sbt plugins in general and the source of the Flyway plugin, I see that this is possible, so this has become a documentation issue. I suggest that the SBT Overview page includes a section for custom configurations:

Custom Configurations

The flywayBaseSettings value of the Flyway plugin provides base configuration and task definitions for the plugin. This can be reused in custom configurations other than the those provided for the runtime and test configurations, if projects require it. These settings may be reused as follows:

import org.flywaydb.sbt.FlywayPlugin

lazy val CustomConfig = config("custom") describedAs "A custom config." extend Runtime

lazy val customSettings: Seq[Def.Setting[_]] = Seq(
  flywayUser := "customUser",
  flywayPassword := "customPassword",
  flywayUrl := "jdbc:driver://host:port/db",

lazy val app = (project in file("app")).
  settings(inConfig(CustomConfig)(FlywayPlugin.flywayBaseSettings(CustomConfig) ++ customSettings): _*)

The configuration passed to flywayBaseSettings is use to derive the classpath for locating migrations implemented in Java.

@axelfontaine axelfontaine changed the title sbt task does not use configuration settings Document SBT custom configuration usage May 5, 2016
Copy link

@axelfontaine axelfontaine commented May 5, 2016

Thanks! Docs updated.

Copy link

@autodidacticon autodidacticon commented Jun 8, 2016

This may be an sbt question, but where would the custom configurations in the above example be used? build.scala?

Copy link

@edmondo1984 edmondo1984 commented Jul 30, 2016

Hello, when I try to use the suggested file I get a number of undefined settings,

References to undefined settings:

app/custom:fullClasspath from app/custom:flywayBaseline ((org.flywaydb.sbt.FlywayPlugin) FlywayPlugin.scala:202)

app/custom:fullClasspath from app/custom:flywayInfo ((org.flywaydb.sbt.FlywayPlugin) FlywayPlugin.scala:189)

app/custom:fullClasspath from app/custom:flywayValidate ((org.flywaydb.sbt.FlywayPlugin) FlywayPlugin.scala:186)

app/custom:fullClasspath from app/custom:flywayRepair ((org.flywaydb.sbt.FlywayPlugin) FlywayPlugin.scala:196)

app/custom:fullClasspath from app/custom:flywayMigrate ((org.flywaydb.sbt.FlywayPlugin) FlywayPlugin.scala:183)

Is there anything missing in the doc?

Copy link

@alexnikitchuk alexnikitchuk commented Dec 3, 2016

@edmondo1984 I've faced the same error and fixed that by changing

Copy link

@binshi binshi commented Feb 22, 2018

Currently I am getting
org.flywaydb.core.api.FlywayException: Unable to instantiate JDBC driver: org.postgresql.Driver => Check whether the jar file is present

Am I missing anything in the above setting?

@flyway flyway locked as resolved and limited conversation to collaborators Feb 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants