From bf0651e88b2dd84f4ba6754d621138d0b942e9e0 Mon Sep 17 00:00:00 2001 From: Nikolay Martynov Date: Tue, 17 Jul 2018 13:19:26 -0400 Subject: [PATCH] Make Jar build fail on duplicate files --- gradle/java.gradle | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gradle/java.gradle b/gradle/java.gradle index 522a4fb34b..7d4c4e282a 100644 --- a/gradle/java.gradle +++ b/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