Maven Flyway执行插件

时间:2018-05-07 19:50:37

标签: maven groovy pom.xml maven-plugin flyway

我有一个flyway项目,其中 ANY 调用flyway:migrate我想运行groovy插件来执行一些groovy脚本。这是我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

  <dependencies>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.4.15</version>
    </dependency>
    <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
        <version>5.0.6</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.1.0.jre8</version>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>LOCAL</id>
      <build>
        <plugins>
          <plugin>
              <groupId>org.codehaus.gmaven</groupId>
              <artifactId>groovy-maven-plugin</artifactId>
              <version>2.0</version>
              <executions>
                  <execution>
                      <phase>package</phase>
                      <goals>
                          <goal>execute</goal>
                      </goals>
                      <configuration>
                          <source>${pom.basedir}/fooScript.groovy</source>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
          <plugin>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-maven-plugin</artifactId>
            <version>5.0.6</version>
            <configuration>
              <url>${url}</url>
              <user>${user}</user>
              <password>${pass}</password>
              <locations>${locations}</locations>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

但只有在设置了LOCAL配置文件flyway:migrate时才会执行groovy插件。

如何设置它以便每次调用flyway:migrate时都会运行插件,无论配置文件如何。

1 个答案:

答案 0 :(得分:1)

完全改变方法怎么样?如果你切换到基于Java的Flyway回调,那么你想要实现的目标实际上是微不足道的,而后者又调用了你想要的Groovy脚本。见https://flywaydb.org/documentation/callbacks