使用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方式,不知道问题处在哪里,还请指点一下,感激不尽 ~!
伊谢尔伦2017-04-17 17:15:01
自己來回答一下
是路徑問題導致的,因為flyway的腳本檔案是預設放在src/java/resources/db/migration這個目錄下面的,注意db和migration是父子目錄的關係,但是在idea裡,這個目錄關係src/java/resources/db/migration會顯示成這樣:
,
導致我誤認為是要將腳本放在src/java/resources/db.migration下,但其實開啟檔案目錄會發現其實兩者不一樣
如果你也遇到類似的問題,最好檢查一下路徑