在sbt中添加仅编译时依赖项 [英] Add a compile time only dependency in sbt

查看:106
本文介绍了在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 ),以便可以在任何平台上编译该项目,而不仅仅是OS X.

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" % ???

?

推荐答案

您可以创建自定义

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作为provided范围的依赖项最终出现在pom.xml中.另外,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中添加仅编译时依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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