JUnit5 in multi-module project

Hello,
I’m trying to figure out on how to avoid duplication with JUnit5. We have several modules in our project, each has it’s own build.gradle.

Putting the following code:

test {
    useJUnitPlatform()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}

into each of them makes little sense, is there a way to put this into root build.gradle?
I tried, but it didn’t work for me.