Adds a test case that exercises the multiple-repository -SNAPSHOT issue. #1514

* Create a project "common" which publishes a "bad" artifact.
* Resolve project "dependent" which resolves the "bad" artifact into the cache.
* Publish a new "common" snapshot to a diffferent repository (publishLocal)
* Attempt to build the new project, leading to issues.
This commit is contained in:
Eugene Yokota 2014-08-09 20:41:28 -04:00
parent 6f0b6669f6
commit 899d5295c8
6 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,58 @@
lazy val sharedResolver =
Resolver.defaultShared.nonlocal()
//MavenRepository("example-shared-repo", "file:///tmp/shared-maven-repo-bad-example")
//Resolver.file("example-shared-repo", repoDir)(Resolver.defaultPatterns)
lazy val common = (
project
.settings(
organization := "com.badexample",
name := "badexample",
version := "1.0-SNAPSHOT",
publishTo := Some(sharedResolver),
crossVersion := CrossVersion.Disabled,
publishMavenStyle := (publishTo.value match {
case Some(repo) =>
repo match {
case repo: PatternsBasedRepository => repo.patterns.isMavenCompatible
case _: RawRepository => false // TODO - look deeper
case _: MavenRepository => true
case _ => false // TODO - Handle chain repository?
}
case _ => true
})
)
)
lazy val dependent = (
project
.settings(
// Ignore the inter-project resolver, so we force to look remotely.
resolvers += sharedResolver,
fullResolvers := fullResolvers.value.filterNot(_==projectResolver.value),
libraryDependencies += "com.badexample" % "badexample" % "1.0-SNAPSHOT"
)
)
TaskKey[Unit]("cleanLocalCache") := {
val ivyHome = file(sys.props.get("ivy.home") orElse sys.props.get("sbt.ivy.home") match {
case Some(home) => home
case None => s"${sys.props("user.home")}/.ivy2"
})
val ivyCache = ivyHome / "cache"
val ivyShared = ivyHome / "shared"
val ivyLocal = ivyHome / "local"
def deleteDirContents(dir: String)(base: File): Unit = {
val toDelete = base / dir
streams.value.log.info(s"Deleting: ${toDelete.getAbsolutePath}")
IO.delete(toDelete)
}
Seq(ivyCache, ivyShared, ivyLocal).map(deleteDirContents("com.badexample"))
}
TaskKey[Unit]("dumpResolvers") := {
streams.value.log.info(s" -- dependent/fullResolvers -- ")
(fullResolvers in dependent).value foreach { r =>
streams.value.log.info(s" * ${r}")
}
}

View File

@ -0,0 +1,3 @@
object Common {
def name = "common"
}

View File

@ -0,0 +1,3 @@
object User {
println(Common.name)
}

View File

@ -0,0 +1,31 @@
# First clean any previous test state
> cleanLocalCache
# Validate that a bad dependency fails the compile
$ copy-file changes/BadCommon.scala common/src/main/scala/Common.scala
> common/publish
# Force dep resolution to be successful, then compilation to fail
> dependent/update
-> dependent/compile
# Push new good change to a DIFFERENT repository.
$ copy-file changes/GoodCommon.scala common/src/main/scala/Common.scala
> common/publishLocal
# Force the update task to look for the new -SNAPSHOT.
> dependent/update
$ copy-file changes/BadCommon.scala common/src/main/scala/Common.scala
> common/publish
> dependent/update
$ copy-file changes/GoodCommon.scala common/src/main/scala/Common.scala
> common/publishLocal
> dependent/update
# This should compile now, because Ivy should look at each repository for the most up-to-date file.
> dependent/compile