Reputation: 1706
Our project consists of multiple subprojects which we publish in a local Nexus. Now, when working on a library, we would like to use this library and build the application without having to upload this library to Nexus all the time.
For a prototypical example, consider we have two projects A and B, with B depending on A:
A/build.sbt:
version := 0.1.7
organization := "org.example"
name := "libraryA"
scalaVersion := "2.11.8"
libraryDependencies += "some.external" % "dependency" % "0.1"
B/build.sbt:
version := 0.2.3
organization := "org.example"
name := "applicationB"
scalaVersion := "2.11.8"
libraryDependencies += "some.other.external" % "dependency" % "0.2"
libraryDependencies += "org.example" % "libraryA" % "0.1.7"
Now let's say I want to work on libraryA and want to test my changes by running applicationB. So I check out A and B to some local folders respectively. Our current approaches are the following:
increment the version number in A/build.sbt
and the dependency in B/build.sbt
. Then do
(cd A && sbt publishLocal) && (cd B && sbt compile)
The version incrementation may not be necessary when using a -SNAPSHOT version (but I'm not sure about this); in any case we always need to do the publishLocal call.
add a new build.sbt
that contain both projects A and B:
lazy val A = (project in file("A")).settings(
version := 0.1.7-SNAPSHOT,
organization := "org.example",
name := "libraryA",
scalaVersion := "2.11.8",
libraryDependencies += "some.external" % "dependency" % "0.1"
)
lazy val B = (project in file("B")).settings(
version := "0.2.3",
organization := "org.example"
name := "applicationB"
scalaVersion := "2.11.8"
libraryDependencies += "some.other.external" % "dependency" % "0.2"
).dependsOn(A)
This has the disadvantage that for every combination of applications/libraries we want to currently hack on, we have to create a new build.sbt
file and also this has a lot of duplications from the other build.sbt files.
But it has the advantage that to compile the application with the modified library, we now only have to write sbt B/compile
.
What we ideally want to have is some way to pin specific library versions to specific folders. This should fix a dependency in the transitive graph to the specific version, and it should be possible for this to be a folder that gets compiled then. The process should look like the following:
sbt pin "org.example%libraryA%0.1.7" folder/A
sbt compile
.Is there something like this available in sbt? I've been told by my coworker that ocaml has something like this (it's called opam pin
there).
Upvotes: 0
Views: 632
Reputation: 946
First of all, you can provide versions to your dependencies in Ivy dynamic version format. For example, "1.2.+" or "latest.integration".
To stick to a specific version of dependency you could use sbt-lock plugin. This plugin allows you to 'lock' dynamic version not in build.sbt file but in additional lock.sbt file. It is good idea to put this file under version control. Using plugin's commands 'unlock' and 'relock' you can change locked versions later.
Upvotes: 1