Liquibase maven 插件未使用类路径属性



由于某种原因,当我在liquibase.properties文件中设置Liquibase maven插件时,它没有使用我的属性。当我运行mvn liquibase:update时,我得到以下信息。

[INFO] there are no resolved artifacts for the Maven project.
[INFO] Parsing Liquibase Properties File
[INFO]   File: target/classes/liquibase.properties
[INFO]   'classpath' in properties file is not being used by this task.

因此,更新失败,因为 liquibase 找不到驱动程序并且无法连接到数据库。

我看到了这个SO问题,但他们使用的是liquibase可执行文件而不是maven。我用它作为如何使用liquibase.properties文件的示例。

使用 MS-SQL Server 设置 Liquibase

我看到它在哪里遇到异常 L571 到 L588 异常,但实际异常没有打印出来,所以我不知道错误的原因。

https://github.com/liquibase/liquibase/blob/9ae7f90a0bbbbcec229a0788afa74831db348ced/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/AbstractLiquibaseMojo.java#L573

不是在属性文件中设置类路径,而是必须将驱动程序 jar 作为依赖项放在 maven POM 中。

请参阅 Liquibase Maven 任务的文档,尤其是描述不同 JDBC 依赖项的部分。下面是一个片段:

Maven Liquibase 更新示例

您需要确保包含相关的 JDBC 驱动程序 Maven POM 文件的依赖部分的数据库。

MySQL 示例:

<project>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <!-- Replace with the version of the MySQL driver you want to use -->
            <version>${mysql-version}</version>
        </dependency>
    </dependencies>
</project>

就我而言,这是一个简单的复制和粘贴问题。

liquibase.properties driver的属性以空格结尾。 删除空间后,一切都很好。

driver: com.mysql.cj.jdbc.Driver

driver: com.mysql.cj.jdbc.Driver

这个答案让我朝着正确的方向前进。就我而言,我需要声明 Maven 资源。

<build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
</build>

希望对您有所帮助!

最新更新