title: Gradle and Flyway: Unable to obtain inputstream for resource
body: <p>I have the problem that migrateDb using Flyway in a Gradle project sometimes causes</p>
  
  <pre><code>Unable to obtain inputstream for resource: META-INF/db/mysql/V1__script.sql
  </code></pre>
  
  <p>This error doesn't occur all the time but only sometimes but if it happens it's quite persistent and also a clean/rebuild of the project doesn't solve it.</p>
  
  <p>The SQL script that is mentioned is contained within a JAR file that is referenced from the project as part of a multi module project.</p>
  
  <p>My researched only brought me to <a href="https://github.com/flyway/flyway/issues/702" rel="noreferrer">https://github.com/flyway/flyway/issues/702</a> but this didn't lead me to the right way.</p>
  
  <p>I'm also very confused that flyway is able to find the file during the classpath search but is then not able to get the input stream.</p>
  
  <p>If you should need any further info please ask.</p>
  
  <p><strong>Further debugging:</strong> It seems that the error seems to happen as soon as a new file is added to the DB JAR. After rebuild and migrateDb the error occurs. If I remove the script again the error still occurs although the script is not in the generated JAR anymore. So I guess the classpath for searching for scripts and retrieving input stream is different. Does anybody know what differences there might be?</p>
  
  <p>Complete stack trace:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Gradle Task:</p>
  
  <pre><code>// 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
  }
  </code></pre>
  
  <p>Gradle dependency:</p>
  
  <pre><code>// dependencies
  dependencies {
      [...]
      runtime project(':core:db:mysql')
      [...]
  }
  </code></pre>