flyway-validator-maven-plugin

Maven plugin to fail a build when duplicate flyway revises are found.

License

License

MIT
Categories

Categories

Maven Build Tools Flyway Data Databases
GroupId

GroupId

io.github.jebeaudet
ArtifactId

ArtifactId

flyway-validator-maven-plugin
Last Version

Last Version

0.4.1
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

flyway-validator-maven-plugin
Maven plugin to fail a build when duplicate flyway revises are found.
Project URL

Project URL

https://github.com/jebeaudet/flyway-validator-maven-plugin
Source Code Management

Source Code Management

https://github.com/jebeaudet/flyway-validator-maven-plugin

Download flyway-validator-maven-plugin

How to add to project

<plugin>
    <groupId>io.github.jebeaudet</groupId>
    <artifactId>flyway-validator-maven-plugin</artifactId>
    <version>0.4.1</version>
</plugin>

Dependencies

compile (4)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.3.9
org.apache.maven : maven-core jar 3.3.9
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.4
com.google.guava : guava jar 24.1.1-jre

test (1)

Group / Artifact Type Version
junit : junit jar 4.13.1

Project Modules

There are no modules declared in this project.

MIT license Maven Central

Flyway validator maven plugin

This plugin will help you avoid duplicate revises when working with Flyway. Duplicate revises sometimes happen when concurrent PR are being merged or lunatic developers forget to validate their old PR against the current codebase.

By using this plugin, the build will fail when problematic version numbers are found in the project.

How to use

The plugin is available on Maven central, just add this to your project or parent pom.xml :

<build>
  </plugins>
    <plugin>
      <groupId>io.github.jebeaudet</groupId>
      <artifactId>flyway-validator-maven-plugin</artifactId>
      <version>0.4.1</version>
      <executions>
        <execution>
          <goals>
            <goal>validate-flyway-revises</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

This will make the plugin run in the default verify phase of Maven. While you're free to change the default phase, be aware that to support java revises, this plugin needs to run after the compile phase.

Configuration

The following properties can be configured :

  • Root path of source files;
  • Path for SQL migrations;
  • Base package for .java migrations;
  • Flag to fail the build if invalid SQL filenames are found;
  • Ignore regex when scanning for filenames, useful to filter out automatic save file generated by editors.

This is done in the plugin configuration (default values shown here) :

<plugin>
    <groupId>io.github.jebeaudet</groupId>
    <artifactId>flyway-validator-maven-plugin</artifactId>
    <version>0.4.1</version>
    <configuration>
        <rootPath>/src/main/resources</rootPath>
        <sqlRevisesRootPath>db/migration</sqlRevisesRootPath>
        <javaRevisesPackage>db.migration</javaRevisesPackage>
        <abortBuildOnInvalidFilenames>true</abortBuildOnInvalidFilenames>
        <ignoredFileRegex>.*~$</ignoredFileRegex>
    </configuration>
</plugin>

Example

Here's an example of a failed build :

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.github.jebeaudet:flyway-validator-maven-plugin:0.3.4:validate-flyway-revises (default) on project test-project:
[ERROR] ------------------------------------------------------------------------
[ERROR] Duplicate migration version(s) found : [1.0, 1.0.1].
[ERROR] Details :
[ERROR] FlywayMigration [version=1.0, filename=V1.0__InitialSetup.sql]
[ERROR] FlywayMigration [version=1.0, filename=V1.0__Conflict.sql]
[ERROR] FlywayMigration [version=1.0.1, filename=V1.0.1__AddConstraint.sql]
[ERROR] FlywayMigration [version=1.0.1, filename=V1_0_1__AddAnotherConstraint.java]
[ERROR] ------------------------------------------------------------------------

Question or found a bug?

Open an issue! PR are also welcome.

Versions

Version
0.4.1
0.4
0.3.4
0.3.3
0.3.2
0.3.1
0.3