通过SBT系统属性指定flywayUrl(Specifying flywayUrl through

2019-10-19 07:50发布

使用迁飞与SBT如何能flywayUrl可以通过系统属性(指定-D ),而不是通过build.sbt

我想通过运行命令行迁移,而不会在定义它们指定了所有参数(驱动程序,URL,用户名,密码) build.sbt

该插件文档页面似乎表明,这应该是可能的:

为了重写

系统属性>插件配置

我试着运行它是这样的:

sbt -Dflyway.url=jdbc:h2:file:target/foobar -Dflyway.user=SA flywayMigrate

flyway.url财产似乎有利于中被忽略flywayUrl中定义的属性build.sbt

考虑到这些文件的项目:

build.sbt

libraryDependencies ++= Seq(
    "com.h2database" % "h2" % "1.3.174"
)

seq(flywaySettings: _*)

flywayUrl := "something that should be overriden"

项目/ plugins.sbt

addSbtPlugin("com.googlecode.flyway" % "flyway-sbt" % "2.3")

resolvers += "Flyway" at "http://flywaydb.org/repo"

的src /主/资源/分贝/迁移/ V1__Create_person_table.sql

create table PERSON (
    ID int not null,
    NAME varchar(100) not null
);

运行此命令:

$ sbt -Dflyway.url=jdbc:h2:file:target/foobar -Dflyway.user=SA flywayMigrate

产生这个错误:

Loading /usr/share/sbt/bin/sbt-launch-lib.bash
[info] Loading project definition from /home/fernando/work/scratch/flyway-sbt/foobar/project
[info] Updating {file:/home/fernando/work/scratch/flyway-sbt/foobar/project/}foobar-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to foobar (in build file:/home/fernando/work/scratch/flyway-sbt/foobar/)
[info] Updating {file:/home/fernando/work/scratch/flyway-sbt/foobar/}foobar...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
com.googlecode.flyway.core.api.FlywayException: Invalid JDBC URL (should start with jdbc:) : something that should be overriden
    at com.googlecode.flyway.core.util.jdbc.DriverDataSource.<init>(DriverDataSource.java:82)
    at com.googlecode.flyway.sbt.FlywayPlugin$FlywayOps$.configure$extension1(FlywayPlugin.scala:214)
    at com.googlecode.flyway.sbt.FlywayPlugin$FlywayOps$.configure$extension0(FlywayPlugin.scala:207)
    at com.googlecode.flyway.sbt.FlywayPlugin$Flyway$.apply(FlywayPlugin.scala:193)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26$$anonfun$apply$1.apply$mcI$sp(FlywayPlugin.scala:145)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26$$anonfun$apply$1.apply(FlywayPlugin.scala:145)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26$$anonfun$apply$1.apply(FlywayPlugin.scala:145)
    at com.googlecode.flyway.sbt.FlywayPlugin$.withContextClassLoader(FlywayPlugin.scala:184)
    at com.googlecode.flyway.sbt.FlywayPlugin$.com$googlecode$flyway$sbt$FlywayPlugin$$withPrepared(FlywayPlugin.scala:167)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26.apply(FlywayPlugin.scala:145)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26.apply(FlywayPlugin.scala:145)
    at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:35)
    at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
[error] (*:flywayMigrate) com.googlecode.flyway.core.api.FlywayException: Invalid JDBC URL (should start with jdbc:) : something that should be overriden
[error] Total time: 0 s, completed Feb 7, 2014 3:32:39 PM

Answer 1:

以下是flywayUrl的定义 :

val flywayUrl = settingKey[String]("The jdbc url to use to connect to the database.")

我似乎无法找到如何设置可通过系统属性进行设置。 该插件似乎并不支持它。

随着中说,你应该找到以下build.sbt的解决方案,并能够通过适当的系统属性,将其值设置:

flywayUrl := System.getProperty("flyway.url", "[default]")

sbt没有执行flyway.url集:

$ sbt 'show flywayUrl'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to flyway (in build file:/Users/jacek/sandbox/so/flyway/)
[info] [default]

而当它被设置在命令行:

$ sbt -Dflyway.url=command-line 'show flywayUrl'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to flyway (in build file:/Users/jacek/sandbox/so/flyway/)
[info] command-line

您可能还会发现其他问题时,在建没有定义默认值在命令行设置的设定值? 有用。



文章来源: Specifying flywayUrl through system property in SBT