问题描述
这是一个示例 build.sbt
:
import AssemblyKeys._
assemblySettings
buildInfoSettings
net.virtualvoid.sbt.graph.Plugin.graphSettings
name := "scala-app-template"
version := "0.1"
scalaVersion := "2.9.3"
val FunnyRuntime = config("funnyruntime") extend(Compile)
libraryDependencies += "org.spark-project" %% "spark-core" % "0.7.3" % "provided"
sourceGenerators in Compile <+= buildInfo
buildInfoPackage := "com.psnively"
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, target)
assembleArtifact in packageScala := false
val root = project.in(file(".")).
configs(FunnyRuntime).
settings(inConfig(FunnyRuntime)(Classpaths.configSettings ++ baseAssemblySettings ++ Seq(
libraryDependencies += "org.spark-project" %% "spark-core" % "0.7.3" % "funnyruntime"
)): _*)
目标是让 spark-core "provided"
使其及其依赖项不包含在程序集工件中,而是将它们重新包含在 run
的运行时类路径中code>- 和 test
相关的任务.
The goal is to have spark-core "provided"
so it and its dependencies are not included in the assembly artifact, but to reinclude them on the runtime classpath for the run
- and test
-related tasks.
似乎使用自定义范围最终会有所帮助,但我不知道如何实际导致默认/全局运行/测试任务使用自定义 libraryDependencies
并希望覆盖默认值.我尝试过的事情包括:
It seems that using a custom scope will ultimately be helpful, but I'm stymied on how to actually cause the default/global run/test tasks to use the custom libraryDependencies
and hopefully override the default. I've tried things including:
(run in Global) := (run in FunnyRuntime)
诸如此类都无济于事.
总结:这感觉本质上是web案例的概括,其中servlet-api在提供"范围内,并且运行/测试任务通常分叉一个servlet容器,该容器确实为正在运行的代码提供servlet-api.这里唯一的区别是我没有分叉出一个单独的 JVM/环境;我只想手动增加这些任务的类路径,有效地撤消"提供的"范围,但以一种继续从程序集工件中排除依赖项的方式.
To summarize: this feels essentially a generalization of the web case, where the servlet-api is in "provided" scope, and run/test tasks generally fork a servlet container that really does provide the servlet-api to the running code. The only difference here is that I'm not forking off a separate JVM/environment; I just want to manually augment those tasks' classpaths, effectively "undoing" the "provided" scope, but in a way that continues to exclude the dependency from the assembly artifact.
推荐答案
对于我在 assembly.sbt 中使用的类似案例:
For a similar case I used in assembly.sbt:
run in Compile <<= Defaults.runTask(fullClasspath in Compile, mainClass in (Compile, run), runner in (Compile, run))
现在运行"任务使用所有库,包括标有提供"的库.无需进一步更改.
and now the 'run' task uses all the libraries, including the ones marked with "provided". No further change was necessary.
更新:
@rob 解决方案似乎是唯一适用于最新 SBT 版本的解决方案,只需添加到 build.sbt
中的 settings
即可:
@rob solution seems to be the only one working on latest SBT version, just add to settings
in build.sbt
:
run in Compile := Defaults.runTask(fullClasspath in Compile, mainClass in (Compile, run), runner in (Compile, run)).evaluated,
runMain in Compile := Defaults.runMainTask(fullClasspath in Compile, runner in(Compile, run)).evaluated
这篇关于如何添加“提供"依赖项回到运行/测试任务的类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!