java - flyway 无法识别sql,Unable to scan for SQL migrations in location。
PHP中文网
PHP中文网 2017-04-17 17:13:01
0
1
811

使用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中文网

认证0级讲师

Antworte allen(1)
伊谢尔伦

自己来回答一下
是路径问题导致的,因为flyway的脚本文件是默认放在src/java/resources/db/migration这个目录下面的,注意db和migration是父子目录的关系,但是在idea里,这个目录关系src/java/resources/db/migration会显示成这样:

导致我误认为是要将脚本放在src/java/resources/db.migration下,但其实打开文件目录会发现其实两者不一样
如果你也遇到类似的问题,最好检查一下路径

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage