当前位置: 首页 > 知识库问答 >
问题:

通过SBT中的系统属性指定flywayUrl

梁磊
2023-03-14

通过sbt使用Flyway,如何通过系统属性(-D)而不是通过构建来指定flywayUrl。sbt

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

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

替代订单

系统属性

我试过这样运行它:

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

但是飞行路线。url属性似乎被忽略,取而代之的是在构建中定义的flywayUrl属性。sbt。

考虑包含以下文件的项目:

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

seq(flywaySettings: _*)

flywayUrl := "something that should be overriden"
addSbtPlugin("com.googlecode.flyway" % "flyway-sbt" % "2.3")

resolvers += "Flyway" at "http://flywaydb.org/repo"
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

共有1个答案

丰赞
2023-03-14

以下是flywayUrl的定义:

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

我似乎找不到如何通过system属性设置设置。插件似乎不支持它。

话虽如此,您应该找到以下构建。sbt解决方案,并能够通过适当的系统属性设置其值:

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

当执行sbt时,无飞行通道。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

当build中没有定义默认值时,您还可以在命令行上找到设置的其他问题设置值?有用的

 类似资料:
  • 问题内容: 我有一个运行的现有jar文件。它是Selenium RC服务器。我希望能够更改JVM httpProxy.host/port/etc系统值。一方面,我可以修改源代码并添加此功能。这将需要一些时间。还有另一种可能的方法吗?就像我自己的JAR(将设置这些JVM属性)在同一个JVM实例中调用selenium- rc(这样,它便能够修改其JVM变量的值)? 问题答案: 您可以使用以下命令在命令

  • Jboss版本:jboss-as-7.1.0.Final 我们能不能加上 在独立满.xml? 我得到以下错误: 在 [行,列]:[479,1] 我有以下条目:

  • 我刚刚开始使用Android Studio 1.3 sdk 24,直到今天,它一直运行良好。我收到有关缓存的错误消息。属性并删除该缓存文件,但现在我收到以下错误消息: 错误:C:\用户\user1.gradle\缓存\2.4\脚本\asLocalRepo15_dhjxrnvsgiyg1ow3dfj4myl7\InitScript\initscript\cache.properties(系统找不到指

  • 22.13.4.通过系统属性执行单独测试 如上所述该机制已经被测试过滤取代 译者注:被取代的东西就先不翻译了 Setting a system property of taskName.single = testNamePattern will only execute tests that match the specified testNamePattern. The taskName can

  • 我已经创建了一个属性文件,并试图在我的SpringDAO类文件中访问它,但是得到了“java.io.FileNotFoundException:config.properties(系统找不到指定的文件)”。我尝试了不同的方案将文件放在不同的文件夹/位置,但遇到了相同的问题。谁能帮我一下吗。以下是代码和结构细节, 在道课上,, 我试图把config.properties文件放在src/main/Re

  • 尝试使用从(本地机器)在远程机器上启动从机(通过Master上的命令行启动从机) slave.jar存在于上面的路径中,它失败了,错误如下: [07/01/13 14:16:11]启动从属代理$sshhread.runjava-jar D:/Jenkins/java.io.系统找不到指定的文件错误:无法启动用于test123的从属代理:系统找不到指定的文件java.lang.IOException