简体   繁体   中英

Maven Flyway Executing Plugin

I have a flyway project where upon ANY invocation of flyway:migrate I want to run the groovy plugin to execute some groovy scripts. Here's my 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>

But the groovy plugin only executes if you do flyway:migrate with the LOCAL profile set.

How do I set it up to have the plugin run every time flyway:migrate is called regardless of profile.

How about changing approaches completely? What you are trying to accomplish is actually quite trivial if you switch to a Java-based Flyway callback, which in turn calls the Groovy script you want. See https://flywaydb.org/documentation/callbacks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM