我可以通過Maven構建(liquibase:update
目標)運行Liquibase更新日誌,沒有任何問題。現在,我想Liquibase使用數據庫憑據和URL從屬性文件加載(db.properties)根據所選擇的Maven的配置文件:從Maven構建中的Liquibase使用的屬性文件加載數據
|-- 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文件本身被定義(在這個問題liquibase using maven with two databases does not work的接受的答案解釋),我希望他們能夠從外部屬性文件中加載。我曾嘗試不同的方法都無濟於事:
1.我使用Maven的resource
元素在POM文件:
<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:更新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文件中引用的數據庫屬性。
任何想法如何實現?