如何在多个子项目之间共享非托管目录?

时间:2013-11-22 07:27:39

标签: scala sbt

在我的项目的根目录中,我有包含非托管jar的lib目录。 我希望这个目录作为我的子项目中的默认非托管目录共享。 我试过这个:

lazy val project1 = Project(
    id = "project1",
    base = file("project1"),
    settings = buildSettings,
    dependencies = Seq(otherProject))   

project1.settings(unmanagedBase <<= baseDirectory { base => base.asFile.getParentFile() })    

不幸的是,当我执行“show unmanagedBase”时,我获得了“./project1/lib”而不是“./lib”。 似乎我获得父母基础的设置没有效果。 欢迎任何帮助。

1 个答案:

答案 0 :(得分:0)

再次感谢您的回答,它确实有效! 我不得不在你的小DSL上添加一行,以便将它们添加到unmanagedJars中:

    def dependsOnSource(dir: String): Seq[Setting[_]] = {
      import Keys._
      Seq(unmanagedSourceDirectories in Compile <<= (unmanagedSourceDirectories in Compile, baseDirectory in ThisBuild) { (srcDirs, base) => (base / dir ) +: srcDirs },
baseDirectory in ThisBuild) { (srcDirs, base) => (base / dir ) +: srcDirs },
          unmanagedJars in Compile <++= (baseDirectory in ThisBuild) map { base =>
            ((base / dir) ** "*.jar").classpath
           },

          unmanagedSourceDirectories in Test <<= (unmanagedSourceDirectories in Test, baseDirectory in ThisBuild) { (srcDirs, base) => (base / dir ) +: srcDirs })
    }
    implicit def p2source(p: Project): SourceDepHelper = new SourceDepHelper(p)
    final class SourceDepHelper(p: Project) {
      def dependsOnSource(dir: String): Project =
        p.settings(Dependencies.dependsOnSource(dir): _*)
    }