当 retrieveManaged 为真时,如何跳过在提供的范围内检索依赖项?

How to skip retrieving dependencies in provided scope when retrieveManaged is true?

只要我在build.sbt中设置retrieveManaged := true,似乎sbt总是检索所有依赖项。

我有一些依赖项配置为 provided,我不需要将它们检索到目录 lib_managed/

如何告诉 sbt?

provided模块配置的目的是:

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

来自 Maven's docs(SBT 使用 Ivy,在这种情况下它重用了 Maven 的约定)。


retrieveManaged := true 的目的是:

insulate your builds from the ivy cache being cleared

来自SBT's FAQs


因此,我认为 provided 依赖项仍然检索到 retrieveManaged := true 下的 lib_managed 是有道理的。

也许您想将 sbt-assembly 视为捆绑您的应用程序(包括处理 provided 依赖项)的一种方式,而不是使用 retrieveManaged.

经过几天的搜索,我找到了一个完全符合我要求的 sbt 插件。 https://github.com/xerial/sbt-pack

虽然它与 lib_managed 无关,但它会在没有提供的情况下将所有依赖项检索到 target/pack/lib 中。并且target/pack可以直接分发,不需要无用的jar。这正是我需要的。