Gradle,Tika - 排除一些依赖包,制作“胖罐”太胖 [英] Gradle, Tika - Exclude some dependency packages making a "fat jar" too fat

查看:219
本文介绍了Gradle,Tika - 排除一些依赖包,制作“胖罐”太胖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,它可以用一些众所周知的文档格式(.docx,.odt,.txt等)创建Lucence索引。

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

Tika是提取文本的理想选择,但它似乎是使我的脂肪瓶气球达到62 MB的罪魁祸首。

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

为了制作脂肪罐,我正在做这个在我的build.gradle:

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
}

当我去 gradle dependencies 时,Tika的确有好几百个......他们中的大多数显然是我做的不需要。

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

是否有已知的Gradle方法来排除/过滤某些依赖关系?

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

具体到Tika:如果有人知道如何识别哪些依赖关系处理哪些文件类型,那也是非常有用的......

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

推荐答案

查看 Gradle依赖管理。你可以通过模块,组或者二者排除依赖:

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'
}

不知道Tika,但这可能是一个单独的问题。阅读Tika文档并检查Jars中的 META-INF 目录可能是一个好主意。

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.

这篇关于Gradle,Tika - 排除一些依赖包,制作“胖罐”太胖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆