Skip to content
This repository was archived by the owner on Apr 8, 2021. It is now read-only.

Commit 17d25cc

Browse files
bjaglinjrudolph
authored andcommitted
Disable cached resolution for ignoreMissingUpdate (#184)
Before 7992dc9, a custom, non-cached-resolution-aware update task was used to generate the report that the tree is based on, effectively ignoring the cached resolution flag at the project level. Starting 7992dc9, this plugin, when run with sbt 0.13.8 or sbt 1.2.5+, relies on cached-resolution-backed reports for projects that have the engine enabled via `updateOptions`. Other 1.x releases are not directly impacted as sbt had a buggy implementation of the feature anyway, see sbt/sbt#3761. Cached resolution has the side effect of generating an ivy report with artificial module descriptors which makes it hard to reconstruct the tree without inlining sbt internals (see below), so this effectively ignores it *for the purpose of the tree generation*, even if the project enabled it for the regular report. ModuleId( org.scala-sbt.temp, temp-resolve-e2a956132f02c038285b41b374c02f5838076f37, 1.0 ) https://github.com/sbt/librarymanagement/blob/984de6f/ivy/src/main/scala/sbt/internal/librarymanagement/ivyint/CachedResolutionResolveEngine.scala#L137
1 parent d2dd796 commit 17d25cc

File tree

6 files changed

+43
-2
lines changed

6 files changed

+43
-2
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
sudo: false
22
language: scala
33
jdk: oraclejdk8
4+
dist: trusty
45
script:
56
- sbt ";^test ;^scripted"
67

@@ -12,4 +13,4 @@ before_cache:
1213
cache:
1314
directories:
1415
- $HOME/.ivy2/cache
15-
- $HOME/.sbt
16+
- $HOME/.sbt

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
* [#184](https://github.com/jrudolph/sbt-dependency-graph/pull/184): Fix regression in 0.10.0-RC1 for recent sbt versions when
5+
`cachedResolution` (with coursier turned off). Thanks [@bjaglin](https://github.com/bjaglin) for the report and the fix.
6+
37
## Version 0.10.0-RC1 (2019-07-24)
48
* [#136](https://github.com/jrudolph/sbt-dependency-graph/pull/136): Added `dependencyBrowseTree` to open a searchable dependency tree in the browser.
59
Thanks, [@pcejrowski](https://github.com/pcejrowski) for contributing this feature.

src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,27 @@ object DependencyGraphSettings {
3737

3838
def baseSettings = Seq(
3939
ivyReportFunction := ivyReportFunctionTask.value,
40+
41+
// disable the cached resolution engine (exposing a scoped `ivyModule` used directly by `updateTask`), as it
42+
// generates artificial module descriptors which are internal to sbt, making it hard to reconstruct the
43+
// dependency tree
44+
updateOptions in ignoreMissingUpdate := updateOptions.value.withCachedResolution(false),
45+
ivyConfiguration in ignoreMissingUpdate :=
46+
// inTask will make sure the new definition will pick up `updateOptions in ignoreMissingUpdate`
47+
SbtAccess.inTask(ignoreMissingUpdate, Classpaths.mkIvyConfiguration).value,
48+
ivyModule in ignoreMissingUpdate := {
49+
// concatenating & inlining ivySbt & ivyModule default task implementations, as `SbtAccess.inTask` does
50+
// NOT correctly force the scope when applied to `TaskKey.toTask` instances (as opposed to raw
51+
// implementations like `Classpaths.mkIvyConfiguration` or `Classpaths.updateTask`)
52+
val is = new IvySbt((ivyConfiguration in ignoreMissingUpdate).value)
53+
new is.Module(moduleSettings.value)
54+
},
55+
56+
// don't fail on missing dependencies
4057
updateConfiguration in ignoreMissingUpdate := updateConfiguration.value.withMissingOk(true),
4158

4259
ignoreMissingUpdate :=
43-
// inTask will make sure the new definition will pick up `updateConfiguration in ignoreMissingUpdate`
60+
// inTask will make sure the new definition will pick up `ivyModule/updateConfiguration in ignoreMissingUpdate`
4461
SbtAccess.inTask(ignoreMissingUpdate, Classpaths.updateTask).value,
4562

4663
filterScalaLibrary in Global := true)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
scalaVersion := "2.12.9"
2+
3+
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.28"
4+
updateOptions := updateOptions.value.withCachedResolution(true)
5+
6+
TaskKey[Unit]("check") := {
7+
val report = (ivyReport in Test).value
8+
val graph = (asciiTree in Test).value
9+
10+
def sanitize(str: String): String = str.split('\n').drop(1).mkString("\n")
11+
val expectedGraph =
12+
"""default:cachedresolution_2.12:0.1.0-SNAPSHOT
13+
| +-org.slf4j:slf4j-api:1.7.28
14+
| """.stripMargin
15+
require(sanitize(graph) == sanitize(expectedGraph), "Graph for report %s was '\n%s' but should have been '\n%s'" format (report, sanitize(graph), sanitize(expectedGraph)))
16+
()
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % sys.props("project.version"))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> check

0 commit comments

Comments
 (0)