gpt4 book ai didi

Gradle 和 Flyway : Unable to obtain inputstream for resource

转载 作者:行者123 更新时间:2023-12-01 12:38:10 35 4
gpt4 key购买 nike

我遇到的问题是在 Gradle 项目中使用 Flyway 进行 migrateDb 有时会导致

Unable to obtain inputstream for resource: META-INF/db/mysql/V1__script.sql

此错误并非一直发生,而是有时发生,但如果发生,它会非常持久,并且项目的清理/重建也无法解决它。

提到的 SQL 脚本包含在一个 JAR 文件中,该文件作为多模块项目的一部分从项目中引用。

我的研究只带我到 https://github.com/flyway/flyway/issues/702但这并没有引导我走向正确的道路。

我也很困惑,flyway 能够在类路径搜索期间找到文件,但随后无法获取输入流。

如果您需要任何进一步的信息,请询问。

进一步调试:似乎只要将新文件添加到 DB JAR 就会发生错误。重建和 migrateDb 后发生错误。如果我再次删除脚本,尽管脚本不再在生成的 JAR 中,但仍然会发生错误。所以我猜想搜索脚本和检索输入流的类路径是不同的。有人知道可能有什么不同吗?

完整的堆栈跟踪:
Caused by: org.flywaydb.core.api.FlywayException: Unable to obtain inputstream for resource: META-INF/db/mysql/V1__script.sql
at org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource.loadAsString(ClassPathResource.java:84)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.scanForMigrations(SqlMigrationResolver.java:139)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:99)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:49)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.collectMigrations(CompositeMigrationResolver.java:122)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.doFindAvailableMigrations(CompositeMigrationResolver.java:104)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:90)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:43)
at org.flywaydb.core.internal.info.MigrationInfoServiceImpl.refresh(MigrationInfoServiceImpl.java:114)
at org.flywaydb.core.internal.command.DbValidate$2.call(DbValidate.java:164)
at org.flywaydb.core.internal.command.DbValidate$2.call(DbValidate.java:157)
at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:75)
at org.flywaydb.core.internal.command.DbValidate.validate(DbValidate.java:157)
at org.flywaydb.core.Flyway.doValidate(Flyway.java:1280)
at org.flywaydb.core.Flyway.access$100(Flyway.java:71)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1176)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1168)
at org.flywaydb.core.Flyway.execute(Flyway.java:1650)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1168)
at org.flywaydb.gradle.task.FlywayMigrateTask.run(FlywayMigrateTask.java:28)
at org.flywaydb.gradle.task.AbstractFlywayTask.runTask(AbstractFlywayTask.java:382)

Gradle 任务:
// task that migrates the database
task migrateDb(type: org.flywaydb.gradle.task.FlywayMigrateTask) {
// parse hibernate config
def hibernateConfig = parseHibernateConfigByStageParameter()

// set config
url = hibernateConfig.url
driver = hibernateConfig.driver
user = hibernateConfig.username
password = hibernateConfig.password
locations = [ "classpath:${flywayDbPath}/${hibernateConfig.dbType}" ]
table = 'schema_version'
outOfOrder = true
ignoreMissingMigrations = true
}

Gradle 依赖:
// dependencies
dependencies {
[...]
runtime project(':core:db:mysql')
[...]
}

最佳答案

在进一步的测试中,我注意到错误似乎是由于 Gradle 守护进程。添加 --no-daemon到 migrateDb 调用工作正常,不会触发错误。

这对我来说很好。

关于Gradle 和 Flyway : Unable to obtain inputstream for resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47841129/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com