From cf0fef5a85e54200c699267d00ce0ece5f179aba Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 13 Jan 2016 12:56:28 -0500 Subject: [PATCH] Inter-project dependency tracking. Fixes #2266 Adds `trackInternalDependencies` and `exportToInternal` settings. These can be used to control whether to trigger compilation of a dependent subprojects when you call `compile`. Both keys will take one of three values: `TrackLevel.NoTracking`, `TrackLevel.TrackIfMissing`, and `TrackLevel.TrackAlways`. By default they are both set to `TrackLevel.TrackAlways`. When `trackInternalDependencies` is set to `TrackLevel.TrackIfMissing`, sbt will no longer try to compile internal (inter-project) dependencies automatically, unless there are no `*.class` files (or JAR file when `exportJars` is `true`) in the output directory. When the setting is set to `TrackLevel.NoTracking`, the compilation of internal dependencies will be skipped. Note that the classpath will still be appended, and dependency graph will still show them as dependencies. The motivation is to save the I/O overhead of checking for the changes on a build with many subprojects during development. Here's how to set all subprojects to `TrackIfMissing`. lazy val root = (project in file(".")). aggregate(....). settings( inThisBuild(Seq( trackInternalDependencies := TrackLevel.TrackIfMissing, exportJars := true )) ) The `exportToInternal` setting allows the dependee subprojects to opt out of the internal tracking, which might be useful if you want to track most subprojects except for a few. The intersection of the `trackInternalDependencies` and `exportToInternal` settings will be used to determine the actual track level. Here's an example to opt-out one project: lazy val dontTrackMe = (project in file("dontTrackMe")). settings( exportToInternal := TrackLevel.NoTracking ) --- .../sbt/librarymanagement/TrackLevel.scala | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 librarymanagement/src/main/scala/sbt/librarymanagement/TrackLevel.scala diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/TrackLevel.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/TrackLevel.scala new file mode 100644 index 000000000..e92b37d68 --- /dev/null +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/TrackLevel.scala @@ -0,0 +1,33 @@ +package sbt.librarymanagement + +/** + * An enumeration defining the tracking of dependencies. A level includes all of the levels + * with id larger than its own id. For example, Warn (id=3) includes Error (id=4). + */ +object TrackLevel { + case object NoTracking extends TrackLevel { + override def id: Int = 0 + } + case object TrackIfMissing extends TrackLevel { + override def id: Int = 1 + } + case object TrackAlways extends TrackLevel { + override def id: Int = 10 + } + + private[sbt] def apply(x: Int): TrackLevel = + x match { + case 0 => NoTracking + case 1 => TrackIfMissing + case 10 => TrackAlways + } + + def intersection(a: TrackLevel, b: TrackLevel): TrackLevel = + if (a.id < b.id) a + else b + def intersectionAll(vs: List[TrackLevel]): TrackLevel = vs reduceLeft intersection +} + +sealed trait TrackLevel { + def id: Int +}