Gradle和Flyway:无法获得资源的输入流

时间:2017-12-15 23:31:24

标签: gradle flyway

我遇到的问题是在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')
    [...]
}

2 个答案:

答案 0 :(得分:1)

在进一步测试期间,我注意到错误似乎是因为Gradle Daemon。将--no-daemon添加到migrateDb调用可以正常工作,并且不会触发错误。

现在对我来说很好。

答案 1 :(得分:0)

事实证明,我正在部署旧的.war,它是由不再存在的.sql文件构建的。 然后我通过运行How tall should the top of the tree be? 10 Flat Tree: ******************* ******************* ******************* ******************* ******************* ******************* ******************* ******************* ******************* ******************* <<<<<<< <<<<<<< <<<<<<<

来解决此问题