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.