在 sbt 中添加仅编译时依赖项

编程入门 行业动态 更新时间:2024-10-22 10:45:37
本文介绍了在 sbt 中添加仅编译时依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想向一个仅用于编译的 sbt 项目添加一个依赖项.它也不应该在运行时类路径上,也不应该在已发布的 POM 中以任何形式可见.

I would like to add a dependency to an sbt project which is only used for compilation. Neither should it be on the runtime class path, nor should it be visible in any form in the published POM.

这个想法是添加一个仅存根的库(OrangeExtensions),以便项目可以在任何平台上编译,而不仅仅是操作系统十.

The idea is to add a stub only library (OrangeExtensions) so that the project can be compiled on any platform not just OS X.

有没有可能是这样的:

libraryDependencies += "com.yuvimasory" % "orange-extensions" % "1.3.0" % ???

?

推荐答案

您可以创建自定义 依赖 configuration (实际上,当您在项目中使用私有宏时,这种情况变得如此普遍,我希望 SBT 提供一个).

You can create a custom dependency configuration for this (actually, this is getting so common when you use private macros in your project, I wish SBT provided one).

在build.sbt:

// a 'compileonly' configuation ivyConfigurations += config("compileonly").hide // some compileonly dependency libraryDependencies += "commons-io" % "commons-io" % "2.4" % "compileonly" // appending everything from 'compileonly' to unmanagedClasspath unmanagedClasspath in Compile ++= update.value.select(configurationFilter("compileonly"))

那个依赖不会出现在publish和好友生成的pom.xml中.

That dependency will not appear in the pom.xml generated by publish and friends.

几乎有这样的配置可用:provided 配置.除了 provided 最终在 pom.xml 作为具有 provided 范围的依赖项.另外,provided 的意思是运行时本身在运行时提供这个",而不是运行时不需要这个".

There almost is such a configuration available: the provided configuration. Except that provided ends up in the pom.xml as a dependency with provided scope. Also, provided means "the runtime itself provides this at runtime", not "this is not needed at runtime".

更多推荐

在 sbt 中添加仅编译时依赖项

本文发布于:2023-07-14 21:52:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107254.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:sbt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!