在JAR中选择性地包含依赖项 [英] Selectively include dependencies in JAR

查看:103
本文介绍了在JAR中选择性地包含依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Scala编写的库,该库使用Bouncy Castle并具有大量依赖项.当我滚动一个jar时,我可以滚动一个具有 all 依赖项(包括scala)的胖" jar,它的大小大约为19 MB,或者我可以滚动一个瘦的jar,而它不t具有依赖性,但只有几百KB.

I have a library that I wrote in Scala that uses Bouncy Castle and has a whole bunch of dependencies. When I roll a jar, I can either roll a "fat" jar that has all the dependencies (including scala), which weighs in around 19 MB, or I can roll a skinny jar, which doesn't have dependencies, but is only a few hundred KB.

问题是我需要在我的库中包含Bouncy Castle类/jar,因为如果运行时不在类路径上,则会抛出各种异常.

The problem is that I need to include the Bouncy Castle classes/jar with my library, because if its not on the classpath at runtime, all kinds of exceptions get thrown.

所以,我认为理想的情况是,是否可以通过某种方式使Maven或SBT在要获取的jar中包含 some 而不是 all 依赖项滚.在编译时需要一些依赖关系,而在运行时则需要不需要,例如Scala标准库.有什么办法可以做到这一点?

So, I think the ideal situation is if there is some way that I can get either Maven or SBT to include some but not all dependencies in the jar that gets rolled. Some dependencies are needed at compile-time, but not at run time, such as the Scala standard libraries. Is there some way to get that to happen?

谢谢!

推荐答案

我会从

I would try out the sbt proguard plugin from https://github.com/nuttycom/sbt-proguard-plugin . It should be able to weed out the classes that are not in use.

这篇关于在JAR中选择性地包含依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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