我正在尝试使用gradle和java制作一个测试应用程序,它使用几个使用java服务提供者接口的库。我想这意味着我需要修改 META-INF
但我不知道该怎么做。
我得到的错误是 An SPI class of type org.apache.lucene.codecs.codec with name
lucene50公司 does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classpath supports the following names [ SimpleText]
我想我需要把spi信息转换成meta-inf,但我不知道该如何处理gradle。
具体来说,我尝试在以下构建文件中使用lucene和hadoop JAR:
apply plugin: 'java'
sourceCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile group:'org.apache.lucene', name:'lucene-core', version:'5.0.0'
compile group:'org.apache.lucene', name:'lucene-queryparser', version:'5.0.0'
compile group:'org.apache.lucene', name:'lucene-analyzers-common', version:'5.0.0'
compile group:'org.apache.lucene', name:'lucene-facet', version:'5.0.0'
compile group:'org.apache.lucene', name:'lucene-codecs', version:'5.0.0'
compile group:'org.apache.hadoop', name:'hadoop-hdfs', version:'2.6.0'
compile group:'org.apache.hadoop', name:'hadoop-core', version:'1.2.1'
compile group:'org.apache.hadoop', name:'hadoop-common', version:'2.6.0'
}
jar
{
from {configurations.compile.collect {it.isDirectory() ?it:zipTree(it) }}
manifest
{
attributes 'Main-Class': 'LuceneTest'
}
}
1条答案
按热度按时间yh2wf1be1#
两个
lucene-core
以及lucene-codecs
图书馆提供org.apache.lucene.codecs.Codec
实现,所以它们都有META-INF/services/org.apache.lucene.codecs.Codec
服务文件。当合并所有依赖项时,两个文件都被添加到jar文件中,但是lucene只看到lucene-codecs
一个。您可以在中手动合并服务文件jar
任务,如本文中所述,它基本上查找所有服务文件并将它们组合在一起。更简单的解决方案可能是使用gradleshadow插件。如果你把这个加到
build.gradle
,使用shadowJar
任务而不是jar
任务应该做你想做的。