我有一个使用Maven构建的Spring Boot项目,在其中我已经包含了Flyway:
pom.xml:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.5.0</version>
</dependency>
以及application.properties文件:
#LOCAL
spring.datasource.url=jdbc:postgresql://localhost:5432/theDatabase
spring.datasource.username=theRightUser
spring.datasource.password=theRightPassword
当我运行应用程序时,它按预期工作。
但是,我正在尝试从命令行运行mvn flyway: clean
,但似乎无法正确识别配置:
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.4.4:clean (default-cli) on project my-service: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password! -> [Help 1]
我尝试在application.properties文件中添加spring.flyway属性(user/pass/url),但是它给了我相同的错误。我需要做什么才能让flyway像应用程序正常运行时那样从application.properies读取?
编辑:我已经取得了一些进展:通过在pom.xml中添加以下内容,我能够将我的application.properties作为flyway配置文件进行引用:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.5.0</version>
<configuration>
<configFiles>${project.basedir}/src/main/resources/application.properties</configFiles>
</configuration>
</plugin>
现在,我在那个文件中有flyway.url
、flyway.user
和flyway.password
。 这使我能够从命令行运行flyway目标,但不完全是我想要的解决方案。 我正在研究使用此插件,尝试将属性读入pom.xml文件,然后在flyway-maven-plugin
的<configuration>
区域中使用这些值。
<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>${project.basedir}/src/main/resources/application.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
这将使我能够做到这一点:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.5.0</version>
<configuration>
<url>${spring.datasource.url}</url>
<user>${spring.datasource.username}</user>
<password>${spring.datasource.password}</password>
</configuration>
</plugin>
properties-maven-plugin
来实现这个目标。 - pennstatephil