Gradle, set testImplementation custom transitive dependency version

January 29, 2024

Parsing DB Rider config: dbunit.yml

New version of spring boot declares new version of snakeyaml which does not allow to use !! in any of attributes. According to docs to set factory one need to use datatypeFactory: !!com.github.database.rider.core.configuration.DBUnitConfigTest$MockDataTypeFactory {} (10)

According to gradle docs, dependency can have constraint on version, but It didn’t work for testImplementation. I found other workaround

configurations {
customTestImplementation.extendsFrom(testImplementation)
}

configurations.customTestImplementation {
    resolutionStrategy.eachDependency { 
        if(it.getRequested().group == "org.yaml" && it.getRequested().name == "snakeyaml) {
        it.useVersion("1.27")
    }
}

sourceSets {
    test {
        runtimeClassPath += configurations.customTestImplementation
        compileClassPath += configurations.customTestImplementation
    }
}

Both Gradle dep tree and intellij claim that snakeyaml, a transitive dependency of db-rider is set to 1.27. But tests were still failing. Instead of digging further I just used annotation configuration approach in place of yml


2022-2024