krenkz
krenkz

Reputation: 470

What is the difference between Flyway Core and Flyway Maven Plugin?

I am using Flyway in my Spring-Boot project (in Eclipse with maven) with

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
</dependency>

and I ran into some interesting issues.

The whole thing worked fine until I failed a migration (because of a typo in the schema syntax). I tried to run fly:repair and I got this error

Failed to execute goal org.flywaydb:flyway-maven-plugin:6.4.1:repair (default-cli) on project springboot: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!

Now, the curious thing I do not understand is that if I add all the information into pom.xml

<properties>
        <flyway.user>databaseUser</flyway.user>
        <flyway.password>databasePassword</flyway.password>
        <flyway.url>urlAddress</flyway.url>
</properties>

it builds. But if I add the information to my application.properties file

spring.flyway.user=databaseUser
spring.flyway.password=databasePassword
spring.flyway.url=urlAddress

the same error message occurs.

According to Baedlung Database Migrations with Flyway (they are using Flyway Maven Plugin), it does not matter where you configure Flyway. So I wonder if I should switch to flyway-maven-plugin? I would really like to have all configuration in the .properties file.

Upvotes: 3

Views: 4685

Answers (1)

Vy Do
Vy Do

Reputation: 52526

First thing: Flyway-core for database migration by Java programming code.

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>7.0.0</version>
</dependency>
import org.flywaydb.core.Flyway;

...
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
flyway.migrate();

// Start the rest of the application (incl. Hibernate)
...

Second thing: Flyway-plugin for Maven goal, run by command-line.

<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>4.0.3</version> 
</plugin>

and

mvn clean flyway:migrate -Dflyway.configFile=myFlywayConfig.properties

You can choose first thing or second thing, depend on your preference (Database migration by Java code or by command)

Upvotes: 6

Related Questions