Home  >  Q&A  >  body text

java - flyway 无法识别sql,Unable to scan for SQL migrations in location。

使用flyway的时候出现无法找到sql文本的异常,构建工具是用的gradle,开发工具idea,以下是相关代码
gradle.properties

flyway.url= jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8
flyway.user= root
flyway.password= 123456

build.gradle

group 'scheduleTest'
version '1.0-SNAPSHOT'
buildscript{
    repositories{
        mavenCentral()
    }
    dependencies{
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.+")
        classpath 'org.flywaydb:flyway-gradle-plugin:3.2.+'
    }
}
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'idea'
apply plugin: 'org.flywaydb.flyway'

sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.2+")
    testCompile("org.springframework.boot:spring-boot-starter-test:1.2+")
    runtime("mysql:mysql-connector-java:5.1.+")
    compile("org.springframework.boot:spring-boot-starter-data-jpa:1.2.+")
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

db.migration路径

报错信息

* What went wrong:
Execution failed for task ':flywayMigrate'.
> Error occurred while executing flywayMigrate
Unable to scan for SQL migrations in location: classpath:db/migration
Unable to determine URL for classpath location: db/migration (ClassLoader: java.net.URLClassLoader@1239a1bd)

datasource配置是没有问题的,因为可以成功执行gradle flywayClean命令将数据库所有表清除,然后sql命名也是遵循V<version>__<name>.sql方式,不知道问题处在哪里,还请指点一下,感激不尽 ~!

PHP中文网PHP中文网2764 days ago769

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:15:01

    Answer it yourself
    It’s caused by a path problem, because flyway’s script files are placed under the directory src/java/resources/db/migration by default. Note that db and migration are parent-child directories, but in idea, This directory relationship src/java/resources/db/migration will be displayed like this:
    ,
    led me to mistakenly think that the script was placed under src/java/resources/db.migration, but in fact Open the file directory and you will find that the two are actually different. If you encounter similar problems, it is best to check the path.

    reply
    0
  • Cancelreply