Make Jar build fail on duplicate files
MODIFY
gradle/java.gradle
gradle/java.gradle
@@ -30,6 +30,23 @@ if (configurations.find { it.name == 'jmh' }) {
eclipse.classpath.plusConfigurations += [configurations.jmh]
}
+jar {
+ /*
+ Make Jar build fail on duplicate files
+
+ By default Gradle Jar task can put multiple files with the same name
+ into a Jar. This may lead to confusion. For example if auto-service
+ annotation processing creates files with same name in `scala` and
+ `java` directory this would result in Jar having two files with the
+ same name in it. Which in turn would result in only one of those
+ files being actually considered when that Jar is used leading to very
+ confusing failures.
+
+ Instead we should 'fail early' and avoid building such Jars.
+ */
+ duplicatesStrategy = 'fail'
+}
+
task packageSources(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource

Make Jar build fail on duplicate files