How do I correctly output META-INF when libraries use SPIs using gradle?
Both the lucene-core
and lucene-codecs
libraries provide org.apache.lucene.codecs.Codec
implementations, so they both have a META-INF/services/org.apache.lucene.codecs.Codec
service file. When you merge all your dependencies, both files are added to the jar file, but Lucene only sees the lucene-codecs
one. You could merge the service files manually in the jar
task, as in this post, which basically finds all the service files and combines them. The easier solution is probably to use something like the Gradle Shadow plugin.
If you add this to build.gradle
, using the shadowJar
task instead of the jar
task should do what you want.
buildscript { repositories { jcenter() } dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.1' }}apply plugin: 'com.github.johnrengelman.shadow'shadowJar { mergeServiceFiles()}