如何在SBT中获取内部项目依赖jar路径

时间:2012-10-04 13:52:04

标签: sbt

我在SBT中实现自定义部署任务,我需要将所有必需的jar复制到部署文件夹。 我可以使用update TaskKey获取所有外部依赖项的路径。不幸的是,updateReport不包含内部依赖项。 这是我的简单配置

val deploy = TaskKey[Unit]("deploy","deploy")

lazy val projectA = Project(id=project-a,
settings=Project.defaultSettings)

lazy val projectB = Project(id=project-b,
settings=Project.defaultSettings) dependsOn(projectA)

lazy val projectC = Project(id=project-c,
settings=Project.defaultSettings, ++ Seq(deployTask)) dependsOn(projectB)

val deployTask = deploy <<= (update) map {(updateReport) =>
val externalDependency = updateReport.allFiles //paths to all external dependencies are available here
//project-a.jar and project-b.jar are not here
}

所以,问题是如何获得内部项目依赖的绝对路径,即project-a.jar,project-b.jar

1 个答案:

答案 0 :(得分:3)

如果设置exportJars属性:

exportJars := true

然后

exportedProducts in Compile

应该为您提供项目的jar文件的路径:

> show export-jars
[info] true
> show exported-products
[info] List(Attributed(/Users/luke/Work/myproject/server/target/scala-2.9.2/server_2.9.2-0.3-SNAPSHOT.jar))
[success] Total time: 0 s, completed Oct 5, 2012 11:29:51 PM