flyway.properties 文件不能用作 pom.xml 配置替代

flyway.properties file not working as pom.xml configuration alternative

我需要设置 flyway 迁移,我不想将密码和用户名放入 pom.xml,我创建了 flyway.properties 文件,但它不起作用,我收到此错误

Failed to execute goal org.flywaydb:flyway-maven-plugin:6.5.1:clean (default-cli) on project entesting: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!

flyway.properties 文件与 pom.xml

在同一目录中
flyway.user=sa
flyway.password=passwordForThis
flyway.url=jdbc:sqlserver://172.23.176.144;database=DB_Name
flyway.locations=filesystem:src/main/resources/db/migration
flyway.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver

pom.xml flyway 插件配置:

        <plugin>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-maven-plugin</artifactId>
            <version>6.5.1</version>
            <configuration>
                <url>jdbc:sqlserver://172.23.176.144;database=DB_Name</url>
                <user>sa</user>
                <password>passwordForThis</password>
            </configuration>
        </plugin>

总而言之,我不想在 pom.xml 中添加密码、用户名等(有效),我希望它在 flyway.propeties.

除了直接将其放入 maven pom.xml 之外,还可以通过多种方式配置 Flyway。请参阅有关 configuring the maven plugin

的文档

您显示的属性文件的内容看起来像 flyway.conf 文件的内容。 Flyway 将搜索并自动加载 <user-home>/flyway.conf 配置文件(如果存在)。

也可以将 Flyway 指向一个或多个额外的配置文件。这是通过如下提供系统 属性 flyway.configFiles 来实现的:

mvn -Dflyway.configFiles=path/to/myAlternativeConfig.conf flyway:migrate

有关详细信息,请参阅 https://flywaydb.org/documentation/maven/#config-files

也可以使用 Maven settings.xml 文件存储数据库用户和密码:

<settings>
   <servers>
       <server>
           <!-- By default Flyway will look for the server with the id 'flyway-db' -->
           <!-- This can be customized by configuring the 'serverId' property -->
           <id>flyway-db</id>
           <username>myUser</username>
           <password>mySecretPwd</password>
       </server>
   </servers>
</settings>