sbt 程序集:去重 module-info.class [英] sbt assembly: deduplicate module-info.class

查看:42
本文介绍了sbt 程序集:去重 module-info.class的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在组装我的 uber jar 时收到以下错误:

I get the following error when assembling my uber jar:

java.lang.RuntimeException: deduplicate: 发现不同的文件内容在以下内容中:[错误]/Users/jake.stone/.ivy2/cache/org.bouncycastle/bcprov-jdk15on/jars/bcprov-jdk15on-1.61.jar:module-info.class[错误]/Users/jake.stone/.ivy2/cache/javax.xml.bind/jaxb-api/jars/jaxb-api-2.3.1.jar:module-info.class

java.lang.RuntimeException: deduplicate: different file contents found in the following: [error] /Users/jake.stone/.ivy2/cache/org.bouncycastle/bcprov-jdk15on/jars/bcprov-jdk15on-1.61.jar:module-info.class [error] /Users/jake.stone/.ivy2/cache/javax.xml.bind/jaxb-api/jars/jaxb-api-2.3.1.jar:module-info.class

我不是最新的 java 技术,但假设我不能简单地丢弃这些类之一.

I am not up to date with java technology, but assume I cannot simply discard one of these classes.

谁能告诉我可以使用什么 mergeStrategy 来安全地编译 uber jar?

Can someone tell me what mergeStrategy I can use to safely compile the uber jar?

推荐答案

答案取决于你的环境和你想要达到的目标.

The answer depends on your environment and what you want to achieve.

我在使用 JDK 8 的项目中遇到了同样的问题.JDK 8 不使用文件 module-info.class 因此丢弃该文件是安全的.

I had the same problem with a project using JDK 8. JDK 8 does not use the file module-info.class so it is safe to discard the file.

将以下内容添加到您的 build.sbt:

Add the following to your build.sbt:

assemblyMergeStrategy in assembly := {
  case "module-info.class" => MergeStrategy.discard
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

这只是丢弃文件.

如果您将 JDK 11 与最终用户项目(而不是库)一起使用,那么它也应该是安全的,就像您创建 uber-jar 时包含所有类并且不需要外部依赖项一样.只是用一个简短的测试对其进行了测试(不够彻底,不能说它总是安全的).

If you use JDK 11 with an end user project (not a library) then it should also be safe as if you create the uber-jar all classes are included and no external dependencies are needed. Just tested it with a short test (not thoroughly enough to say it is always safe).

如果您使用 JDK 11 并创建库,那么最好不要创建 uber-jar.在这种情况下,删除 module-info.class 很可能会创建一个不起作用的 jar.在这种情况下,只需依赖库即可.

If you use JDK 11 and create a library then it is better not to create an uber-jar. In this case a dropping of the module-info.class will most likely create a jar that will not work. In this case simply depend on the libraries.

这篇关于sbt 程序集:去重 module-info.class的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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