From 17d25ccc44547c1466b98a73a169ee9bf597b370 Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Sat, 7 Sep 2019 14:03:56 +0200 Subject: [PATCH] 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 https://github.com/sbt/sbt/issues/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 --- .travis.yml | 3 ++- CHANGELOG.md | 4 ++++ .../sbt/graph/DependencyGraphSettings.scala | 19 ++++++++++++++++++- .../cachedResolution/build.sbt | 17 +++++++++++++++++ .../cachedResolution/project/plugins.sbt | 1 + .../cachedResolution/test | 1 + 6 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/sbt-test/sbt-dependency-graph/cachedResolution/build.sbt create mode 100644 src/sbt-test/sbt-dependency-graph/cachedResolution/project/plugins.sbt create mode 100644 src/sbt-test/sbt-dependency-graph/cachedResolution/test diff --git a/.travis.yml b/.travis.yml index 6190c81fb..5a335d2aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ sudo: false language: scala jdk: oraclejdk8 +dist: trusty script: - sbt ";^test ;^scripted" @@ -12,4 +13,4 @@ before_cache: cache: directories: - $HOME/.ivy2/cache - - $HOME/.sbt \ No newline at end of file + - $HOME/.sbt diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd87ebbd..02eb5e41b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + * [#184](https://github.com/jrudolph/sbt-dependency-graph/pull/184): Fix regression in 0.10.0-RC1 for recent sbt versions when + `cachedResolution` (with coursier turned off). Thanks [@bjaglin](https://github.com/bjaglin) for the report and the fix. + ## Version 0.10.0-RC1 (2019-07-24) * [#136](https://github.com/jrudolph/sbt-dependency-graph/pull/136): Added `dependencyBrowseTree` to open a searchable dependency tree in the browser. Thanks, [@pcejrowski](https://github.com/pcejrowski) for contributing this feature. diff --git a/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala b/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala index 2ea3b3cce..bec65daf6 100644 --- a/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala +++ b/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala @@ -37,10 +37,27 @@ object DependencyGraphSettings { def baseSettings = Seq( ivyReportFunction := ivyReportFunctionTask.value, + + // disable the cached resolution engine (exposing a scoped `ivyModule` used directly by `updateTask`), as it + // generates artificial module descriptors which are internal to sbt, making it hard to reconstruct the + // dependency tree + updateOptions in ignoreMissingUpdate := updateOptions.value.withCachedResolution(false), + ivyConfiguration in ignoreMissingUpdate := + // inTask will make sure the new definition will pick up `updateOptions in ignoreMissingUpdate` + SbtAccess.inTask(ignoreMissingUpdate, Classpaths.mkIvyConfiguration).value, + ivyModule in ignoreMissingUpdate := { + // concatenating & inlining ivySbt & ivyModule default task implementations, as `SbtAccess.inTask` does + // NOT correctly force the scope when applied to `TaskKey.toTask` instances (as opposed to raw + // implementations like `Classpaths.mkIvyConfiguration` or `Classpaths.updateTask`) + val is = new IvySbt((ivyConfiguration in ignoreMissingUpdate).value) + new is.Module(moduleSettings.value) + }, + + // don't fail on missing dependencies updateConfiguration in ignoreMissingUpdate := updateConfiguration.value.withMissingOk(true), ignoreMissingUpdate := - // inTask will make sure the new definition will pick up `updateConfiguration in ignoreMissingUpdate` + // inTask will make sure the new definition will pick up `ivyModule/updateConfiguration in ignoreMissingUpdate` SbtAccess.inTask(ignoreMissingUpdate, Classpaths.updateTask).value, filterScalaLibrary in Global := true) diff --git a/src/sbt-test/sbt-dependency-graph/cachedResolution/build.sbt b/src/sbt-test/sbt-dependency-graph/cachedResolution/build.sbt new file mode 100644 index 000000000..e9aef9b55 --- /dev/null +++ b/src/sbt-test/sbt-dependency-graph/cachedResolution/build.sbt @@ -0,0 +1,17 @@ +scalaVersion := "2.12.9" + +libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.28" +updateOptions := updateOptions.value.withCachedResolution(true) + +TaskKey[Unit]("check") := { + val report = (ivyReport in Test).value + val graph = (asciiTree in Test).value + + def sanitize(str: String): String = str.split('\n').drop(1).mkString("\n") + val expectedGraph = + """default:cachedresolution_2.12:0.1.0-SNAPSHOT + | +-org.slf4j:slf4j-api:1.7.28 + | """.stripMargin + require(sanitize(graph) == sanitize(expectedGraph), "Graph for report %s was '\n%s' but should have been '\n%s'" format (report, sanitize(graph), sanitize(expectedGraph))) + () +} diff --git a/src/sbt-test/sbt-dependency-graph/cachedResolution/project/plugins.sbt b/src/sbt-test/sbt-dependency-graph/cachedResolution/project/plugins.sbt new file mode 100644 index 000000000..6fdebb6d6 --- /dev/null +++ b/src/sbt-test/sbt-dependency-graph/cachedResolution/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % sys.props("project.version")) diff --git a/src/sbt-test/sbt-dependency-graph/cachedResolution/test b/src/sbt-test/sbt-dependency-graph/cachedResolution/test new file mode 100644 index 000000000..a5912a391 --- /dev/null +++ b/src/sbt-test/sbt-dependency-graph/cachedResolution/test @@ -0,0 +1 @@ +> check \ No newline at end of file