› ~/

Flyway, SQLite and Java

2020-10-04

It wasn’t clearly documented on flyway’s homepage how to get started with the Java API in combination with SQLite, so I thought I would save a couple of minutes if anyone else is looking for it.

Dependencies

You need to install flyway db and a driver for SQLite as dependencies in the project.

 <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>7.0.0</version>
 </dependency>
 <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.30.1</version>
 </dependency>

Information regarding SQLite driver can be found here

Property names

The property names are defined in the flyway-maven-plugin and all properties should be prefixed with flyway., I guess that makes sense. I spent too much time not realizing this. 🤦‍♂️

If you don’t prefix your url property, you’ll probably end up getting the following error: Unable to connect to the database. Configure the url, user and password!. Which isn’t very helpful if you don’t know that you have to prefix your properties.

Properties properties = new Properties();
properties.setProperty("flyway.url", "jdbc:sqlite:/YOUR_DB_FILE.db");

Hopefully it saved some minutes for someone! ⌚

Written by
Andreas