How to properly configure Liquibase in Spring Boot with Maven plugin so that a I can run diff command using latest version

huangapple go评论76阅读模式
英文:

How to properly configure Liquibase in Spring Boot with Maven plugin so that a I can run diff command using latest version

问题

当我尝试执行 liquibase diff 命令时,我得到了以下错误:

ERROR [liquibase.integration.commandline.Main]: 在运行 Liquibase 时出现意外错误: java.lang.RuntimeException: 无法找到数据库驱动程序: liquibase.ext.hibernate.database.connection.HibernateDriver

我猜这可能与版本或缺少的依赖项有关,所以这是我 POM.XML 文件的一部分:

        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

<properties>
        <java.version>1.8</java.version>
        <kotlin.version>1.4.0</kotlin.version>
        <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
        <mapstruct.version>1.4.0.Beta3</mapstruct.version>
    </properties>

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>3.10.2</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.10.2</version>
                <configuration>
                    <propertyFileWillOverride>true</propertyFileWillOverride>
                    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate5</artifactId>
                        <version>3.10.2</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                        <version>4.1.7.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.data</groupId>
                        <artifactId>spring-data-jpa</artifactId>
                        <version>1.7.3.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-data-jpa</artifactId>
                        <version>${spring-boot.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>

我已经安装了 liquibase 3.10.2 版本 - Mac OS,我使用的是 postgres 数据库。此外,这是我 liquibase 属性文件的一部分:

username=postgres
password=
driver=org.postgresql.Driver
referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUrl=hibernate:spring:com.something.something.models?dialect=org.hibernate.dialect.PostgreSQLDialect```

<details>
<summary>英文:</summary>

When I try to execute ```liquibase diff``` command, I get the following error:

*ERROR [liquibase.integration.commandline.Main]: Unexpected error running Liquibase: java.lang.RuntimeException: Cannot find database driver: liquibase.ext.hibernate.database.connection.HibernateDriver*

I assume it might have something to do with versions or missing dependencies so here is part of my POM.XML file:

```&lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;2.3.1.RELEASE&lt;/version&gt;
        &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
    &lt;/parent&gt;

&lt;properties&gt;
        &lt;java.version&gt;1.8&lt;/java.version&gt;
        &lt;kotlin.version&gt;1.4.0&lt;/kotlin.version&gt;
        &lt;kotlin.compiler.jvmTarget&gt;1.8&lt;/kotlin.compiler.jvmTarget&gt;
        &lt;mapstruct.version&gt;1.4.0.Beta3&lt;/mapstruct.version&gt;
    &lt;/properties&gt;

&lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
            &lt;scope&gt;runtime&lt;/scope&gt;
            &lt;optional&gt;true&lt;/optional&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
            &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
            &lt;scope&gt;runtime&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
            &lt;version&gt;5.2.6.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.liquibase&lt;/groupId&gt;
            &lt;artifactId&gt;liquibase-core&lt;/artifactId&gt;
            &lt;version&gt;3.10.2&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
    &lt;build&gt;
        &lt;sourceDirectory&gt;${project.basedir}/src/main/kotlin&lt;/sourceDirectory&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.liquibase&lt;/groupId&gt;
                &lt;artifactId&gt;liquibase-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.10.2&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;propertyFileWillOverride&gt;true&lt;/propertyFileWillOverride&gt;
                    &lt;propertyFile&gt;src/main/resources/liquibase.properties&lt;/propertyFile&gt;
                &lt;/configuration&gt;
                &lt;dependencies&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.liquibase.ext&lt;/groupId&gt;
                        &lt;artifactId&gt;liquibase-hibernate5&lt;/artifactId&gt;
                        &lt;version&gt;3.10.2&lt;/version&gt;
                    &lt;/dependency&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                        &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
                        &lt;version&gt;4.1.7.RELEASE&lt;/version&gt;
                    &lt;/dependency&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
                        &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
                        &lt;version&gt;1.7.3.RELEASE&lt;/version&gt;
                    &lt;/dependency&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
                        &lt;version&gt;${spring-boot.version}&lt;/version&gt;
                    &lt;/dependency&gt;
                &lt;/dependencies&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;

I've installed liquibase 3.10.2 version - Mac OS and I use postgres. Also, here is part of my liquibase properties file:

username=postgres
password=
driver=org.postgresql.Driver
referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUrl=hibernate:spring:com.something.something.models?dialect=org.hibernate.dialect.PostgreSQLDialect```



</details>


# 答案1
**得分**: 1

我已切换到版本4.0.0并更新了pom.xml如下:

```xml
<plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>4.0.0</version>
    <configuration>
        <propertyFileWillOverride>true</propertyFileWillOverride>
        <propertyFile>src/main/resources/liquibase.properties</propertyFile>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.liquibase.ext</groupId>
            <artifactId>liquibase-hibernate5</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.1.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.7.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
    </dependencies>
</plugin>

现在,运行mvn liquibase:diff命令会生成差异文件。

英文:

I've switched to version 4.0.0 and updated pom.xml to following:

&lt;plugin&gt;
                &lt;groupId&gt;org.liquibase&lt;/groupId&gt;
                &lt;artifactId&gt;liquibase-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;4.0.0&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;propertyFileWillOverride&gt;true&lt;/propertyFileWillOverride&gt;
                    &lt;propertyFile&gt;src/main/resources/liquibase.properties&lt;/propertyFile&gt;
                &lt;/configuration&gt;
                &lt;dependencies&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.liquibase.ext&lt;/groupId&gt;
                        &lt;artifactId&gt;liquibase-hibernate5&lt;/artifactId&gt;
                        &lt;version&gt;4.0.0&lt;/version&gt;
                    &lt;/dependency&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                        &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
                        &lt;version&gt;4.1.7.RELEASE&lt;/version&gt;
                    &lt;/dependency&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
                        &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
                        &lt;version&gt;1.7.3.RELEASE&lt;/version&gt;
                    &lt;/dependency&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;javax.validation&lt;/groupId&gt;
                        &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
                        &lt;version&gt;2.0.1.Final&lt;/version&gt;
                    &lt;/dependency&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
                        &lt;version&gt;${spring-boot.version}&lt;/version&gt;
                    &lt;/dependency&gt;
                &lt;/dependencies&gt;
            &lt;/plugin&gt;

Now, mvn liquibase:diff command generates diff file.

huangapple
  • 本文由 发表于 2020年8月19日 23:30:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63490378.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定