DEV Community

Salad Lam
Salad Lam

Posted on

Adding Liquibase plugin into Apache Maven managed project

Setup

Content of database/liquibase.properties

driver: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/databasename
username: root
password: password
Enter fullscreen mode Exit fullscreen mode

Add the following into Maven's pom.xml file

<build>
    <plugins>
        <!-- other plugins ... -->
        <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>4.27.0</version>
            <configuration>
                <propertyFile>${project.basedir}/database/liquibase.properties</propertyFile>
                <!-- must use relative path because this will save into `databasechangelog` table
                rollback will fail if `FILENAME` not match -->
                <changeLogFile>database/changelog.xml</changeLogFile>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>8.0.33</version>
                </dependency>
            </dependencies>
        </plugin>
   </plugins>
</build>
<!-- other sections ... -->
Enter fullscreen mode Exit fullscreen mode

And put the database change file changelog.xml into database directory of project root.

Command

Apply all changes into the database

mvn liquibase:update
Enter fullscreen mode Exit fullscreen mode

Available commands can refer to here.

Imagine monitoring actually built for developers

Billboard image

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay