从属性文件加载数据,以供 Maven 构建中的 Liquibase 使用
我可以通过maven build(目标)运行Liquibase更改日志,而不会出现任何问题。现在,我希望 Liquibase 使用从属性文件(db.properties)加载的数据库凭据和 URL,具体取决于所选的 Maven 配置文件:liquibase:update
|-- pom.xml
`-- src
`-- main
`-- resources
|-- local
| `-- db.properties
|-- dev
| `-- db.properties
|-- prod
| `-- db.properties
`-- db-changelog-master.xml
`-- db-changelog-1.0.xml
3 个属性文件中的每一个都如下所示:
database.driver = oracle.jdbc.driver.OracleDriver
database.url = jdbc:oracle:thin:@<host_name>:<port_number>/instance
database.username = user
database.password = password123
现在,这些属性不是在POM文件本身中定义的(如这个问题的公认答案中所述,使用具有两个数据库的maven的maven不起作用),我希望它们从外部属性文件中加载。我尝试了不同的方法,但无济于事:
1. 我在 POM 文件中使用了 Maven 的资源
元素:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<changeLogFile>db.changelog-master.xml</changeLogFile>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<resources>
<resource>
<directory>src/main/resources/local</directory>
</resource>
</resources>
</build>
<properties>
<liquibase.url>${database.url}</liquibase.url>
<liquibase.driver>${database.driver}</liquibase.driver>
<liquibase.username>${database.username}</liquibase.username>
<liquibase.password>${database.password}</liquibase.password>
</properties>
</profile>
<profile>
<id>dev</id>
<build>
<resources>
<resource>
<directory>src/main/resources/dev</directory>
</resource>
</resources>
</build>
<properties>
<liquibase.url>${database.url}</liquibase.url>
<liquibase.driver>${database.driver}</liquibase.driver>
<liquibase.username>${database.username}</liquibase.username>
<liquibase.password>${database.password}</liquibase.password>
</properties>
</profile>
</profiles>
2. 我尝试使用属性 Maven 插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/local/db.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
当我运行 liquibase:update maven 目标时,我收到以下错误:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.1.0:update (default-cli) on project my-project: The driver has not been specified either as a parameter or in a properties file
似乎无法解析 POM 文件中引用的数据库属性。
任何想法如何实现这一点?