3

I created a jar file, created from multiple jars (I used Gradle Shadow plugin in this case).

It turned out that the file contains duplicate files in /META-INF. Most of them are multiple license.txt from the original jar files, but some of them are Spring factories, which I'm interested in.

This behaviour seems common when using various fatjar-like tools with Maven or Gradle, and it looks like it is not prohibited by any means.

I've checked that java.lang.ClassLoader#getResources will return these entries as a list of the same URLs, eg.:

  • jar:file:/C:/temp/myJar.jar!/META-INF/spring.factories
  • jar:file:/C:/temp/myJar.jar!/META-INF/spring.factories

so once I get the URL, there's no way back to getting the contents of all duplicated files, programmatically.

Can Java process such duplicate files, somehow?

Or, maybe more general, is it a valid and supported situation, from specs' point of view, to have a jar with duplicate files inside? I've checked Jar File Specification and it didn't give me a clue, either.

Adrian Rodriguez
  • 3,232
  • 2
  • 24
  • 34
psiqta
  • 75
  • 5

1 Answers1

2

In maven-shade-plugin this is done with an AppendingTransformer.

My interpretation of the gradle plugin documentation you are using is that this is done this way:

shadowJar {
  append('META-INF/spring.factories')
}
idelvall
  • 1,536
  • 15
  • 25