Override h2 verison in Springboot

Viewed 244

I am trying to override the H2 database version in a spring-boot project with:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.h2database:h2' ext['h2.version'] = '1.4.197'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.18.2'
}

But my IDE tells me the "=" is unexpected on the h2.version line.

My full build.gradle is:

plugins {
    id 'org.springframework.boot' version '2.5.12'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.h2database:h2' ext['h2.version'] = '1.4.197'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.18.2'
    implementation group: 'com.graphhopper.external', name: 'jackson-datatype-jts', version: '1.0-2.7'
    implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '5.6.0.Final'
    implementation group: 'org.orbisgis', name: 'h2gis', version: '1.5.0'
}

tasks.named('test') {
    useJUnitPlatform()
}

How do I override the H2 version?

1 Answers

ext['h2.version'] = '1.4.197' is setting a property named h2.version. It should be done outside of the dependencies block:

ext['h2.version'] = '1.4.197'

dependencies {
    // …
    runtimeOnly 'com.h2database:h2'
    // …
}
Related