SBT:如何使子项目在开发期间相互依赖,并且在作为maven文物发布时也是如此?

时间:2014-02-05 12:22:44

标签: scala sbt

在开发期间,我使用以下语法:

lazy val root = project.in(file(".")).dependsOn(runner)

但是对于发布我需要这个:

libraryDependencies += ... % ... % ... 

但是我不希望在开发期间存在libraryDependencies这个东西,否则我需要发布每个编译都很烦人的本地。有没有什么好的解决方案可以在我发布时将其评论并重新发布?

1 个答案:

答案 0 :(得分:4)

您不应将子项目添加为libraryDependencies,即使在publish期间也不应如此。

现在要发布模块,您可以创建一个简单的publishSettings变量:

val publishSettings : Seq[Setting[_]] = Seq(
    publishTo := Some("your company releases" at "http://yourrepository"),
    credentials += Credentials(
      "Repository",
      "repositoryUrl",
      "username",
      "password!"
    ),
    publishMavenStyle := true,
    publishArtifact in Test := false,
    pomIncludeRepository := { _ => true }
  )

lazy val main = Project(..).aggregate(subproject1, subproject2, // etc)

lazy val subproject1 = Project(
  settings = Project.defaultSettings ++ publishSettings
);
lazy val subproject2 = Project(
  settings = Project.defaultSettings ++ publishSettings
).dependsOn(subproject1)

SBT现在将自动在后台重新编译依赖项。请勿将其添加为libraryDependencies,只能将其添加到dependsOn