【问题标题】:Flyway doesn't execute in default phaseFlyway 在默认阶段不执行
【发布时间】:2014-11-17 08:23:27
【问题描述】:

我正在处理 Maven 项目,并且我添加了 flyway 插件,它执行 sql 脚本以进行测试。我想确保这些脚本不会被意外执行,而只是使用 "mvn ... flyway:migrate"

我发现 migrate 操作的默认阶段是 pre-integration-test,但是当我运行 mvn clean install flyway 时'没有被调用(这对我来说没问题,但我想知道为什么它们没有被调用)。

这是pom.xml的一部分:

        <plugin>             
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-maven-plugin</artifactId>  
            <version>3.0</version>             
            <configuration>
                <driver>${db-driver-name}</driver>
                <url>${db-url}</url>
                <user>${db-user-name}</user>
                <password>${db-user-password}</password>
                <locations>
                    <location>filesystem:./src/main/resources/db/scripts/V${db-version}</location>
                </locations>
                <schemas>
                    <schema>schema</schema>
                </schemas>
            </configuration>
            <dependencies> 
                <dependency>
                    <groupId>oracle.jdbc</groupId>
                    <artifactId>ojdbc6</artifactId>
                    <version>11.2.0.4</version>
                </dependency>
            </dependencies>
        </plugin>

提前致谢!

【问题讨论】:

    标签: java maven maven-plugin flyway


    【解决方案1】:

    您可以做的是默认将flyway.skip 设置为true,并且仅在您想要运行迁移时将其设置为false。

    此外,预集成测试是在打包之后进行的。这就是为什么不使用 mvn clean package 调用它的原因。

    【讨论】:

    • 是的,我编辑了问题,我正在考虑 mvn clean install
    【解决方案2】:

    请确认您的&lt;plugin&gt; 部分在您希望它运行的模块中独立。

    不仅在&lt;pluginManagement&gt; 部分内。

    【讨论】:

      【解决方案3】:

      一个插件可能包含多个目标,因为在这种情况下,您不仅有迁移,还有清理、信息等。除非您在项目的执行中定义要运行的目标,否则它们将不会运行.

      您必须在插件 xml 定义的执行块中指定目标,如下所示:

        <plugin>             
              <groupId>org.flywaydb</groupId>
              <artifactId>flyway-maven-plugin</artifactId>  
              <version>3.0</version> 
              <executions>
                  <execution>
                      <goals>
                          <goal>migrate</goal>
                      </goals>
                  </execution>
              </executions>            
              <configuration>
                  <driver>${db-driver-name}</driver>
                  <url>${db-url}</url>
                  <user>${db-user-name}</user>
                  <password>${db-user-password}</password>
                  <locations>
                      <location>filesystem:./src/main/resources/db/scripts/V${db-version}</location>
                  </locations>
                  <schemas>
                      <schema>schema</schema>
                  </schemas>
              </configuration>
              <dependencies> 
                  <dependency>
                      <groupId>oracle.jdbc</groupId>
                      <artifactId>ojdbc6</artifactId>
                      <version>11.2.0.4</version>
                  </dependency>
              </dependencies>
          </plugin>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-23
        • 2022-06-16
        • 2020-12-09
        • 2013-10-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多