我创建了一个简单的spring boot Gradle项目。我想我的数据库将通过flyway插件从SQL文件创建时,我的项目是建立。下面是我的代码片段。项目已成功生成,但SQL文件中提到的表未在mydb1数据库中创建。
建筑gradle文件
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id "org.flywaydb.flyway" version "5.0.7"
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.flywayex'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
task createDatabase() {
doLast {
println 'Hello Gradle to copy'
flyway {
println "Flyway: "
driver = 'org.h2.Driver'
url = 'jdbc:h2:mem:mydb1'
user = 'sa'
locations = ['filesystem:db/migration']
println "Flyway: $locations"
}
}
}
build.dependsOn createDatabase
V1。初始化1。sql文件放在资源/数据库/迁移下
CREATE TABLE users (
id bigint(20) NOT NULL AUTO_INCREMENT,
username varchar(100) NOT NULL,
first_name varchar(50) NOT NULL,
last_name varchar(50) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY UK_username (username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我错过了什么?