Gradle, Tika - Exclude some dependency packages making a “fat jar” too fat

心已入冬 提交于 2019-12-12 01:25:17

问题


I'm making an app which creates Lucence indices on a handful of well-known document formats (.docx, .odt, .txt, etc.).

Tika is ideal for extracting the text but it appears to be the culprit in making my fat jar balloon to 62 MB.

To make the fat jar I'm doing this in my build.gradle:

buildscript {
    repositories { jcenter() }
    dependencies { // fatjar
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4' }
}
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
    baseName = project.name
    classifier = null
    version = project.version
}

task copyJarToBin(type: Copy) {
    from shadowJar
    into "D:/My Documents/Software projects/Operative/" + project.name
}

When I go gradle dependencies, Tika does indeed appear to have hundreds... most of them obviously I don't need.

Is there a known Gradle way of excluding/filtering out certain dependencies?

Specific to Tika: if anyone knows how to identify which dependencies handle which file types, that would be very useful too...


回答1:


Take a look at Gradle dependency management. You can exclude dependencies by module, group or both:

compile('library:with-a-lot-of-deps:1.0') {
    exclude module: 'weird-extension'
    exclude group: 'microsoft-extensions'
    exclude group: 'adobe-extensions', module: 'pdf-extension' 
}

And you can also remove dependencies from all configurations:

configurations {
    all*.exclude group: 'all-the-unneeded-extensions'
}

No idea about Tika, but that would probably be a separate question anyway. Might be a good idea to read on Tika docs and inspect META-INF directory in the Jars.



来源:https://stackoverflow.com/questions/42333087/gradle-tika-exclude-some-dependency-packages-making-a-fat-jar-too-fat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!