在各个阶段传播飞路配置文件

Spreading flyway profiles over phases

我正在尝试使用 flyway-maven-plugin 创建单独的配置文件,但阶段定义无法正常工作。这意味着当我使用这两个配置文件时,我在执行时出错,因为我猜 "drop-create-database" 使用来自 "migrate-database" 的配置,因此它失败了。有人知道如何解决吗?

    <profiles>
    <profile>
        <id>drop-create</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.flywaydb</groupId>
                    <artifactId>flyway-maven-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <driver>net.sourceforge.jtds.jdbc.Driver</driver>
                        <table>MIGRATION_LOG</table>
                        <sqlMigrationPrefix>EMP_</sqlMigrationPrefix>
                        <skip>false</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <id>drop-create-database</id>
                            <!-- Need to garantee order of execution -->
                            <phase>package</phase>
                            <goals>
                                <goal>clean</goal>
                                <goal>migrate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>migrate</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.flywaydb</groupId>
                    <artifactId>flyway-maven-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <driver>net.sourceforge.jtds.jdbc.Driver</driver>
                        <table>MIGRATION_LOG</table>
                        <sqlMigrationPrefix>ALL_</sqlMigrationPrefix>
                        <skip>false</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <id>migrate-database</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>migrate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

您必须指定每次执行而不是每个插件的配置。否则同一插件的后续配置将覆盖之前的配置。

这意味着您的 pom.xml 应该看起来像这样:

<profiles>
<profile>
    <id>drop-create</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>3.1</version>
                <executions>
                    <execution>
                        <id>drop-create-database</id>
                        <!-- Need to garantee order of execution -->
                        <phase>package</phase>
                        <goals>
                            <goal>clean</goal>
                            <goal>migrate</goal>
                        </goals>
                        <configuration>
                            <driver>net.sourceforge.jtds.jdbc.Driver</driver>
                            <table>MIGRATION_LOG</table>
                            <sqlMigrationPrefix>EMP_</sqlMigrationPrefix>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>
<profile>
    <id>migrate</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>3.1</version>
                <executions>
                    <execution>
                        <id>migrate-database</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>migrate</goal>
                        </goals>
                        <configuration>
                            <driver>net.sourceforge.jtds.jdbc.Driver</driver>
                            <table>MIGRATION_LOG</table>
                            <sqlMigrationPrefix>ALL_</sqlMigrationPrefix>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>