【问题标题】:Chaining Maven Flyway commands链接 Maven Flyway 命令
【发布时间】:2011-08-09 15:11:07
【问题描述】:

如何使用 Maven 将 Flyway 命令链接到单个命令中?

例如,我想运行mvn initialize flyway:clean,然后运行mvn initialize compile flyway:migrate。但是,mvn initialize flyway:clean compile flyway:migrate 失败了。

谢谢!

【问题讨论】:

    标签: maven-2 maven maven-plugin maven-3 flyway


    【解决方案1】:

    我刚刚检查过

    mvn initialize flyway:clean compile flyway:migrate
    

    同时使用 Maven 2.2.1 和 Maven 3.0.3,并且每次都能正常工作。

    你能仔细检查一下吗?如果您认为确实发现了问题,请在Issue Tracker 中提出问题,并附上重现问题的必要步骤,我会尽快修复。

    【讨论】:

      【解决方案2】:

      这将使您能够链接 maven 步骤,只需在其中添加您想要的目标

      <profile>
              <id>clean-migrate</id>
              <build>
                  <plugins>
                      <plugin>
                          <artifactId>maven-resources-plugin</artifactId>
                          <executions>
                              <execution>
                                  <id>process-resources1</id>
                                  <goals>
                                      <goal>resources</goal>
                                  </goals>
                                  <!-- Populate the database before querydsl-sql runs -->
                                  <phase>generate-sources</phase>
                              </execution>
                          </executions>
                      </plugin>
                      <plugin>
                          <artifactId>maven-compiler-plugin</artifactId>
                          <configuration>
                              <source>1.6</source>
                              <target>1.6</target>
                          </configuration>
                      </plugin>
                      <plugin>
                          <groupId>com.googlecode.flyway</groupId>
                          <artifactId>flyway-maven-plugin</artifactId>
                          <executions>
                              <execution>
                                  <id>process-resources2</id>
                                  <goals>
                                      <goal>clean</goal>
                                      <goal>migrate</goal>
                                  </goals>
                                  <phase>generate-sources</phase>
                              </execution>
                          </executions>
                          <version>1.4.2</version>
                          <configuration>
                              <driver>oracle.jdbc.driver.OracleDriver</driver>
                              <url>jdbc:oracle:thin:@${database-hostname}:${database-port}:${database-sid}</url>
                              <user>${database-username}</user>
                              <password>${database-password}</password>
                              <schemas>${database-schema}</schemas>
                              <table>schema_history</table>
                              <initialVersion>0.1.00</initialVersion>
                              <initialDescription>Base Migration</initialDescription>
                          </configuration>
                      </plugin>
                  </plugins>
              </build>
          </profile>
      

      您的 settings.xml 中还需要以下内容

      <profile>
        <id>inject-flyway-properties</id>
          <properties>
            <database-hostname>${env.DB_HOSTNAME}</database-hostname>
            <database-port>${env.DB_PORT}</database-port>
            <database-username>${env.DB_USER}</database-username>
            <database-password>${env.DB_PASSWORD}</database-password>
            <database-sid>${env.DB_DEFAULT_SID}</database-sid>
            <database-schema>${env.DB_SCHEMA}</database-schema>
          </properties>
      </profile>
      

      【讨论】:

      • 这将使您能够链接 maven 步骤,只需在其中添加您想要的目标。
      【解决方案3】:

      如果我理解文档正确,您必须配置 maven-flyway 插件来完成工作并将其绑定到 maven 的正确阶段,而不是使用默认的 maven 调用,如 mvn clean package 或 mvn clean verify。

      【讨论】:

        【解决方案4】:

        您可以使用profiles 将“命令”捆绑在一起。完成后,您只需调用:

        mvn -Pmy-profile
        

        【讨论】:

          猜你喜欢
          • 2015-07-22
          • 2020-10-29
          • 1970-01-01
          • 2012-06-06
          • 2015-08-28
          • 2016-09-24
          • 1970-01-01
          • 2021-11-08
          • 1970-01-01
          相关资源
          最近更新 更多