Li Haoyi
Li Haoyi

Reputation: 15802

SBT: how to make subprojects depend on each other during dev, and also when published as maven artefacts?

During dev I'm using the following syntax:

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

But for publishing I need to this this:

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

But I don't want the libraryDependencies thing to exist during dev, otherwise i'd need to publishLocal every compile which is annoying. Is there any good solution short of commenting that out and putting it back in whenever i publish?

Upvotes: 3

Views: 505

Answers (1)

flavian
flavian

Reputation: 28511

You shouldn't add sub-projects as libraryDependencies, not even during publish.

Now to publish modules you can create a simple publishSettings variable:

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 will now automatically re-compile dependencies in the background. Don't add them as libraryDependencies, only put them in dependsOn.

Upvotes: 4

Related Questions