Reputation: 1263
I have created a simple spring-boot Gradle project. I want to my database to be created via flyway plugin from SQL file when my project is built. Below is my code snippet. The project gets build successfully but tables mention in SQL files are not created in mydb1 database.
build.gradle file
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.init1.sql file placed under resources/db/migration
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;
what am I missing?
Upvotes: 1
Views: 974
Reputation: 3830
I suspect it can't find your migration scripts. Try either:
locations "filesystem:${project.projectDir}/src/main/resources/db/migration"
or
locations "classpath:db/migration"
Upvotes: 1