将liquibase参数传递给gradle liquibase'update'任务

将liquibase参数传递给gradle liquibase'update'任务

问题描述:

我想将用户名,密码和url liquibase参数作为命令行参数传递给gradle的liquibase更新任务.

I want to pass username, password and url liquibase parameters as a command line parameters to gradle's liquibase update task.

我已按照 liquibase-gradle-plugin 配置插件. 我真正想要实现的是在运行时传递这些数据库参数,而不是在liquibase.properties文件中对其进行硬编码.

I have followed liquibase-gradle-plugin to configure the plugin. What I actually want to achieve is, pass these database parameters at runtime instead of hardcoding them in liquibase.properties file.

我可以通过将这三个值导出为环境变量并在build.gradle中对其进行访问来做到这一点.但是我想使用命令行参数来实现这一点.

I can do this by exporting these three values as environment variables and access them in build.gradle. But I want to achieve this using commandline parameters.

我尝试了

gradle更新--url = jdbc:postgresql://localhost:5432/liquibase_cmd_test-用户名= ###-密码= ### -PrunList = main

gradle update --url=jdbc:postgresql://localhost:5432/liquibase_cmd_test --username=### --password=### -PrunList=main

但它给出错误为

未知的命令行选项'--url'.

Unknown command-line option '--url'.

我认为gradle之下是Java,因此您应该可以执行以下操作. -D参数设置系统属性.

I think that underneath gradle is Java, so you should be able to do something like this. The -D argument sets a system property.

gradle -Dliquibase.url=<your url> -Dliquibase.username=<username> -Dliquibase.password=<password> update -PrunList=main