Gradle-如何在itest源集中执行flyway迁移
编辑:问题解决了,因为我注意到:Gradle-如何在itest源集中执行flyway迁移,gradle,integration-testing,flyway,Gradle,Integration Testing,Flyway,编辑:问题解决了,因为我注意到: itest未运行,因为test阶段有一些错误,因此下一步itest将无法继续 itest也适用于迁移,我已经仔细检查了日志,可以确认这一点。我在itestlogflyway中搜索,我看到了 所以这个问题是个错误。对不起 我有一个源集: 主要 试验 itest 而itest的定义如下:(project/gradle/integration.gradle) 当我运行gradle-test-itest时,我看到应用了迁移,但当我运行gradle-itest时,
未运行,因为itest
阶段有一些错误,因此下一步test
将无法继续itest
也适用于迁移,我已经仔细检查了日志,可以确认这一点。我在itest
logitest
中搜索,我看到了李>flyway
- 主要
- 试验
- itest
itest
的定义如下:(project/gradle/integration.gradle
)
当我运行gradle-test-itest
时,我看到应用了迁移,但当我运行gradle-itest
时,它们没有应用。我明白,如果我强制itest
在test
之后执行,就像现在一样,我可以确保;但有时我只想运行itest
如何更改此脚本?迁移任务运行始终是因为触发了
gradle flywayMigrate
任务
也许某个插件更改了默认设置,使test
任务依赖于flywayMigrate
因此,如果您希望自己的任务触发flywayMigrate
,您可以这样做:
itest.dependsOn flywayMigrate
// reference:
clean.dependsOn flywayRepair # To repair the Flyway metadata table
build.dependsOn flywayMigrate # To migrate the schema to the latest version
您如何为正常测试任务应用迁移?您可能需要对itest执行同样的操作。是的,但在
build.gradle
中,这是noflywayMigrate
部分。所以我不知道怎么做。@BjørnVester很抱歉,我忘了提到我使用Spring Boot,所以有FlywayAutoconfiguration
。尝试了,但是integration.gradle
的解析失败。似乎任务没有在任何地方定义。顺便说一句,我使用的是Spring BootI,我的意思是flywayMigrate
没有在任何地方找到/定义。这里没有使用gradle flyway插件,这就是flywayMigrate不可用的原因。但是我想做Flyway.migrate()
就像Spring Boot在FlywayAutoconfiguration
中做的那样,因为flywayMigrate
总是需要Flyway{}
属性,比如user
,url
和password
,而且我看不到从application.yml
读取这些属性的简单方法,特别是当它们是特定于配置文件时。@WesternGun有spring boot自动运行Flyway docs:,他们提供了示例项目:抱歉,但这不是我的情况:我想在另一个源集中迁移Flyway,itest
,无论是main
还是test
。该示例是一个非常基本的示例,只包含main
和test
sourceset。
itest.dependsOn flywayMigrate
// reference:
clean.dependsOn flywayRepair # To repair the Flyway metadata table
build.dependsOn flywayMigrate # To migrate the schema to the latest version