【问题标题】:Spreading flyway profiles over phases在各个阶段传播飞行路线剖面
【发布时间】:2015-04-03 02:47:16
【问题描述】:

我正在尝试使用 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>

【问题讨论】:

  • 两次执行的实际执行顺序是什么?
  • 抱歉,我已经修正了描述。当我运行“clean package -Pdrop-create, migrate”时不要猜测它用于“迁移”而不是它自己的“drop-create”配置。

标签: maven flyway


【解决方案1】:

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

这意味着您的 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>

【讨论】:

  • 该死,我以为我试过了……显然我错了!非常感谢,工作正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-11
  • 1970-01-01
  • 2021-07-23
  • 1970-01-01
  • 2016-09-19
  • 2020-08-12
  • 1970-01-01
相关资源
最近更新 更多