我可以在maven pom.xml中使用属性文件进行flyway配置

Gar*_*rry 23 pom.xml maven flyway

<plugin>
    <groupId>com.googlecode.flyway</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>1.7</version>
    <configuration>
        <driver>com.mysql.jdbc.Driver</driver>
        <url>jdbc:mysql://127.0.0.1:3306/db_abc</url>
        <user>db_user</user>
        <sqlMigrationPrefix>V</sqlMigrationPrefix>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我不想在这里提到驱动程序,网址和用户.我已经有一个abc.propertysrc/main/resources.怎么在这里使用该文件?

Séb*_*nec 33

看看吧properties-maven-plugin.它允许您从文件中读取属性,然后在您的pom中使用它们.

添加以下插件定义:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0.0</version>
    <executions>
      <execution>
        <phase>initialize</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>src/main/resources/abc.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

如果abc.properties包含:

jdbc.driver = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://127.0.0.1:3306/db_ab
jdbc.user = db_user
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用以下属性:

<!-- language: xml -->

<driver>${jdbc.driver}</driver>
<url>${jdbc.url}</url>
<user>${jdbc.user}</user>
Run Code Online (Sandbox Code Playgroud)

  • 为了将来参考,这很好用,但你需要在调用flay插件之前显式调用mvn initialize,例如`mvn initialize flyway:migrate` (6认同)
  • 如果根据配置文件我有不同的属性文件怎么办?比如对于开发,abc-dev.properties,对于生产 abc-prod.properties (2认同)

小智 5

在 3.0 版本中,您必须使用 configFile,例如:

<configFile>src/main/resources/db/config/flyway.properties</configFile>
Run Code Online (Sandbox Code Playgroud)