【问题标题】:Migrate from jars in flyway maven plugin从flyway maven插件中的jar迁移
【发布时间】:2018-12-28 15:36:57
【问题描述】:

是否可以从 maven flyway 插件中的 jar 迁移?我对 sqls 和 java(编译为类)没有问题,但对 jars 没有成功。类路径设置正确。

【问题讨论】:

    标签: maven jar flyway


    【解决方案1】:

    好的,我已经调试了源代码。 Jar 需要一个特殊的协议,当它被放置在 flyway 命令行工具的 /jars 目录中时,它会被提供给它。在 flyway maven 插件中没有这样的等价物。

    【讨论】:

      【解决方案2】:

      这是对从包含多个 flyway SQL 文件的 jar 工件文件执行 flyway-maven-plugin 的限制的轻微解决方法。

      创建个人资料

      1. 使用 'maven-dependency-plugin:unpack' 将 jar 文件的内容分解到特定目录。
      2. 运行“flyway-maven-plugin”,“位置”仅限于提取的目录。
      3. 不是很漂亮,但很有效。

      这是我的示例配置文件

      <profiles>
          <profile>
              <id>flyway</id>
              <build>
                  <plugins>
                      <plugin>
                          <groupId>org.apache.maven.plugins</groupId>
                          <artifactId>maven-dependency-plugin</artifactId>
                          <version>3.1.1</version>
                          <executions>
                              <execution>
                                  <id>copy</id>
                                  <phase>process-resources</phase>
                                  <goals>
                                      <goal>unpack</goal>
                                  </goals>
                              </execution>
                          </executions>
                          <configuration>
                              <artifactItems>
                                  <artifactItem>
                                      <groupId>com.abc</groupId>
                                      <artifactId>flyway</artifactId>
                                      <version>1.0.0-SNAPSHOT</version>
                                      <type>jar</type>
                                      <overWrite>true</overWrite>
                                      <outputDirectory>${project.build.directory}/jars</outputDirectory>
                                      <destFileName>my-flyway.jar</destFileName>
                                  </artifactItem>
                              </artifactItems>
                              <overWriteReleases>false</overWriteReleases>
                              <overWriteSnapshots>true</overWriteSnapshots>
                          </configuration>
                      </plugin>
                      <plugin>
                          <groupId>org.flywaydb</groupId>
                          <artifactId>flyway-maven-plugin</artifactId>
                          <version>${flyway.version}</version>
                          <configuration>
                              <sqlMigrationSeparator>__</sqlMigrationSeparator>
                              <locations>
                                  <location>filesystem:./target/jars/my-flyway.jar</location>
                              </locations>
                              <url>${flyway.url}</url>
                              <user>${flyway.user}</user>
                              <password>${flyway.password}</password>
                              <schemas>
                                  <schema>my_schema</schema>
                              </schemas>
                              <baselineOnMigrate>true</baselineOnMigrate>
                          </configuration>
                          <dependencies>
                              <dependency>
                                  <groupId>org.postgresql</groupId>
                                  <artifactId>postgresql</artifactId>
                                  <version>${postgresql.version}</version>
                              </dependency>
                          </dependencies>
                      </plugin>
                  </plugins>
              </build>
          </profile>
      </profiles>
      

      然后是maven命令行

      mvn -P flyway clean process-resources flyway:migrate 
      

      【讨论】:

        猜你喜欢
        • 2016-10-24
        • 2018-08-28
        • 2012-06-28
        • 1970-01-01
        • 2013-12-05
        • 2015-01-02
        • 2012-12-18
        • 2012-04-05
        • 2018-12-19
        相关资源
        最近更新 更多