使用 Gradle 8 运行 Liquibase 4 会导致错误找不到参数 [] 的 getMain() 方法

问题描述 投票:0回答:1

我正在使用 Liquibase 4 和 Gradle 8 设置 Spring Boot 3 项目,无论我在 build.gradle 中配置 Liquibase 时如何尝试,在运行任何 liquibase Gradle 脚本时,我总是会收到以下错误:

> Task :update FAILED
liquibase-plugin: Running the 'main' activity...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':update'.
> Could not find method getMain() for arguments [] on task ':update' of type org.liquibase.gradle.LiquibaseTask.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s
1 actionable task: 1 executed

我的

build.gradle.kts
如下:

plugins {
    id("java")
    id("org.springframework.boot") version "3.1.2"
    id("org.liquibase.gradle") version "2.0.4"
}

group = "com.example"

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

liquibase {
    activities.register("main") {
        this.arguments = mapOf(
                "changelogFile" to "src/test/resources/db/changelog/db.changelog-master.yaml",
                "classpath" to "src/test/resources",
                "url" to "jdbc:postgresql://localhost:5432/test",
                "username" to "gpadmin",
                "password" to "gpadmin",
                "driver" to "org.postgresql.Driver",
        )
    }
    runList = "main"
}

configurations.configureEach {
    exclude(group = "org.springframework.boot", module = "spring-boot-starter-json")
    exclude(group = "com.sun.xml.bind")
}

repositories {
    mavenLocal()
    mavenCentral()
}

val springBootVersion = "3.1.2"
val springCloudVersion = "2022.0.3"
val springCloudStarterVersion = "4.0.3"
val pivotalSpringCloudServicesVersion = "4.0.3"
val springCloudContractVersion = "4.0.3"
val springdocVersion = "2.1.0"
val restAssuredVersion = "5.3.1"
val rdf4jVersion = "3.7.7"
val lombokVersion = "1.18.28"

dependencies {
    // Spring boot dependencies
    implementation("org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}")
    implementation("org.springframework.boot:spring-boot-starter-data-r2dbc:${springBootVersion}")
    implementation("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")

    // Database / service related dependencies
    implementation("org.postgresql:r2dbc-postgresql:1.0.2.RELEASE")
    runtimeOnly("org.postgresql:postgresql:42.6.0")

    // Other dependencies
    implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:${springdocVersion}")
    implementation("com.google.guava:guava:32.1.1-jre")
    implementation("org.eclipse.rdf4j:rdf4j-model:${rdf4jVersion}")

    // Lombok
    compileOnly("org.projectlombok:lombok:${lombokVersion}")
    annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
    testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
    testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")

    // Test Dependencies
    testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
    testImplementation("org.springframework.security:spring-security-test:6.1.1")
    testImplementation("org.springframework.cloud:spring-cloud-starter-contract-verifier:${springCloudContractVersion}")
    testImplementation("io.rest-assured:spring-web-test-client:${restAssuredVersion}")
    testImplementation("io.rest-assured:rest-assured-common:${restAssuredVersion}")
    testImplementation("io.projectreactor:reactor-test:3.5.8")

    // Dependencies required for running liquibase for tests
    liquibaseRuntime("org.liquibase:liquibase-core:4.23.0")
    liquibaseRuntime("info.picocli:picocli:4.7.4")
    liquibaseRuntime("org.liquibase.ext:liquibase-hibernate5:4.22.0")
}

tasks.withType<JavaCompile>().configureEach {
    options.encoding = "UTF-8"
    options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
}

tasks.named<Test>("test") {
    useJUnitPlatform()
}

如果有人能告诉我我做错了什么导致了这个错误,我将非常感激。对于我的一生,我在网上找不到任何与此相关的信息。

我创建了一个 GitHub 存储库,可以在其中重现此问题:https://github.com/favna/congenial-fishstick/tree/liquibase-issue。请注意,您查看了这个

liquibase-issue
分支,因为我正在重用之前问题中的同一存储库。

gradle liquibase
1个回答
2
投票

好吧,我可以再次关闭它。真的,我不知道到底发生了什么,因为我已经面临这个问题几天了,但刚刚我将 Gradle 插件从 2.0.4 更新到 2.2.0,这似乎已经修复了它。事实是,我 100% 确定我之前使用过 v2.2.0,尽管当时我的

build.gradle
仍在使用 Groovy 语法,因此 Liquibase 配置是一种非常不同的方式。

FWIW 从现在开始我会坚持

build.gradle.kts
,我很高兴问题得到了解决。

我已将最终更改添加到 GitHub 存储库。

© www.soinside.com 2019 - 2024. All rights reserved.