如何在 Grails 3 Gradle 项目中控制 H2 驱动版本?

How to control H2 driver version in Grails 3 Gradle project?

如何在Grails/Gradle项目中控制H2驱动版本?

运行 Grails 3 应用程序与 H2 有问题我找到了这个答案:Grails accessing H2 TCP server hangs 说明这可能是由驱动程序版本差异引起的。

我的 IDE 报告 Grails 应用程序使用 1.3.176 版本的 H2,而我的服务器有 1.4.190。所以,我想升级应用程序的 H2,但找不到它的定义位置。我找遍了所有的项目文件,没有找到版本定义。

更新

我目前的 build.gradle:

buildscript {
    ext {
        grailsVersion = project.grailsVersion
    }
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0'
        classpath "org.grails.plugins:hibernate:4.3.10.5"
    }
}

plugins {
    id "io.spring.dependency-management" version "0.5.2.RELEASE"
}

version "0.1"
group "multipleparentsgrails"

apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: "asset-pipeline"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"

ext {
    grailsVersion = project.grailsVersion
    gradleWrapperVersion = project.gradleWrapperVersion
}

assets {
    minifyJs = true
    minifyCss = true
}

repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
}

dependencyManagement {
    imports {
        mavenBom "org.grails:grails-bom:$grailsVersion"
    }
    applyMavenExclusions false
}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"

    compile "org.grails.plugins:hibernate"
    compile "org.grails.plugins:cache"
    compile "org.hibernate:hibernate-ehcache"
    compile "org.grails.plugins:scaffolding"

    runtime "org.grails.plugins:asset-pipeline"

    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"

    // Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
    testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'

    console "org.grails:grails-console"
}

task wrapper(type: Wrapper) {
    gradleVersion = gradleWrapperVersion
}

您应该能够像任何其他依赖项一样指定它

runtime "com.h2database:h2:1.4.190"

有许多依赖项可能会使用 H2。 grails、hibernate、其他。

我会参与你的项目。假设它是 $HOME/projects/myproj.

1)做依赖报告。将其通过管道传输到 grep 中,这样您就不必费力地浏览 1,000 行的报告,也不必查看正在使用的 H2 版本。

cd $HOME/projects/myproj
./gradlew dependencies | grep 'H2'

2) 找到最高版本号,然后在你的 build.gradle 中明确包含它以强制每个依赖项使用最新版本:

dependencies {
    // all the other dependencies

    runtime "com.h2database:h2:1.4.190"  // where 1.4.190 is the most
                                         // current version.  as i
                                         // type this it is 1.4.191
                                         // according to maven central

}