duplicate but no duplicate handling strategy has been set – gradle DuplicationStrategy

While using Java and Kotlin with Spring Boot the following exception occurs and it’s quite hard to find how to fix it.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:processResources'.
> Entry ... is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.5.1/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.

The simple solution is to add the following top level config in your gradle file:

tasks.withType<Copy> {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}