我想在我的SBT中包含一个外部项目,例如:
lazy val leonProject = RootProject(uri("https://github.com/epfl-lara/leon.git"))
现在我有一个自定义任务,需要获取此RootProject
的一些文件
如何找到RootProject
已下载的路径?
我尝试了什么
这不存在。
leonProject.baseDirectory // Does not exist. There is no such field.
我试着查看sbt的文档,看看我们可以用RootProject
及其超类ProjectReference
做什么,但我找不到任何东西(我甚至写了一个脚本来从他们的网站上找到相关的信息)。
我尝试模仿sbt eclipse plugin的行为,即关注this和this。但它只会回归"#footest"如果我运行sbt footest
,则永远不执行内部命令,事件。它仅列出激活此命令的项目。
lazy val root = (project in file(".")).settings(
Keys.commands <+= ("footest")((str: String) => {
println("#"+str)
lazy val key = Keys.baseDirectory in ThisBuild
def structure(state: State): BuildStructure = Project.extract(state).structure
Command.single("footest")((state, args) => {
println("executed")
key.get(structure(state).data) match {
case Some(a) => println("The project file "+a)
case None => "Undefined setting '%s'!"
}
state
}
)
}
))
// and call sbt foobar.
在build.sbt文件中,在顶层(对我来说,项目的设置不起作用),请写下以下内容:
lazy val leonLocalBase = SettingKey[File]("leonLocalBase", "local base for leon project")
leonLocalBase := {
val build = loadedBuild.value
val leonUnit = build.units(leonProject.build)
leonUnit.localBase
}
// Now you can use leonLocalBase.value.getAbsolutePath() to retrieve the full path where leon has been downloaded.
答案 0 :(得分:1)
您可以从加载的项目结构中获取它。
import sbt._
import Keys._
object MyBuild extends Build {
val leonLocalBase = SettingKey[File]("leonLocalBase", "local base for leon project")
lazy val root = Project("root", file("."))
.dependsOn(leonProject)
.settings(
leonLocalBase := {
val build = loadedBuild.value
val leonUnit = build.units(leonProject.build)
leonUnit.localBase
}
)
lazy val leonProject = RootProject(uri("https://github.com/epfl-lara/leon.git"))
}