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
This commit is contained in:
Brice Jaglin 2019-09-07 14:03:56 +02:00 committed by Johannes Rudolph
parent d2dd796fd7
commit 17d25ccc44
6 changed files with 43 additions and 2 deletions

View File

@ -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
- $HOME/.sbt

View File

@ -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.

View File

@ -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)

View File

@ -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)))
()
}

View File

@ -0,0 +1 @@
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % sys.props("project.version"))

View File

@ -0,0 +1 @@
> check