Permalink
Browse files

work around 'data has not been loaded' exception when direct dependen…

…cy overridden by newer version
  • Loading branch information...
1 parent 6312978 commit 5fa93ca9f97fc09d27981d1f1667d699c4886208 @harrah committed Feb 15, 2012
View
@@ -141,9 +141,9 @@ final class IvySbt(val configuration: IvyConfiguration)
log.debug("Using inline dependencies specified in Scala" + (if(ivyXML.isEmpty) "." else " and XML."))
val parser = IvySbt.parseIvyXML(ivy.getSettings, IvySbt.wrapped(module, ivyXML), moduleID, defaultConf.name, validate)
- IvySbt.addDependencies(moduleID, dependencies, parser)
IvySbt.addMainArtifact(moduleID)
- IvySbt.addOverrides(moduleID, overrides, ivy.getSettings.getMatcher(PatternMatcher.EXACT_OR_REGEXP))
+ IvySbt.addOverrides(moduleID, overrides, ivy.getSettings.getMatcher(PatternMatcher.EXACT))
+ IvySbt.addDependencies(moduleID, IvySbt.overrideDirect(dependencies, overrides), parser)
(moduleID, parser.getDefaultConf)
}
private def newConfiguredModuleID(module: ModuleID, moduleInfo: ModuleInfo, configurations: Iterable[Configuration]) =
@@ -440,6 +440,20 @@ private object IvySbt
val overrideWith = new OverrideDependencyDescriptorMediator(null, overrideDef.revision)
moduleID.addDependencyDescriptorMediator(overrideID, matcher, overrideWith)
}
+ /** It is necessary to explicitly modify direct dependencies because Ivy gives
+ * "IllegalStateException: impossible to get artifacts when data has not been loaded."
+ * when a direct dependency is overridden with a newer version."*/
+ def overrideDirect(dependencies: Seq[ModuleID], overrides: Set[ModuleID]): Seq[ModuleID] =
+ {
+ def key(id: ModuleID) = (id.organization, id.name)
+ val overridden = overrides.map(id => (key(id), id.revision)).toMap
+ dependencies map { dep =>
+ overridden get key(dep) match {
+ case Some(rev) => dep.copy(revision = rev)
+ case None => dep
+ }
+ }
+ }
/** This method is used to add inline artifacts to the provided module. */
def addArtifacts(moduleID: DefaultModuleDescriptor, artifacts: Iterable[Artifact]): Unit =
@@ -1,6 +1,10 @@
autoScalaLibrary := false
-libraryDependencies += "junit" % "junit" % "4.5" % "test"
+ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache")))
+
+ivyScala <<= (scalaVersion in update, scalaBinaryVersion in update) { (fv, bv) =>
+ Some(new IvyScala(fv, bv, Nil, filterImplicit = false, checkExplicit = false, overrideScalaVersion = false))
+}
InputKey[Unit]("check") <<= inputTask { args =>
(update, args) map {
@@ -1,8 +1,19 @@
+> 'set libraryDependencies := Seq("junit" % "junit" % "3.8.1" % "test")'
+> check 3.8.1
+> 'set dependencyOverrides := Set("junit" % "junit" % "4.5")'
+> check 4.5
+
+> 'set libraryDependencies := Seq("junit" % "junit" % "4.5" % "test")'
> check 4.5
> 'set dependencyOverrides := Set("junit" % "junit" % "3.8.1")'
> check 3.8.1
-> 'set libraryDependencies := Seq("net.databinder" %% "dispatch-http" % "0.8.7" intransitive())'
+> 'set libraryDependencies := Seq("net.databinder" %% "dispatch-http" % "0.8.7")'
> check 0.8.7
> 'set dependencyOverrides := Set("net.databinder" %% "dispatch-http" % "0.8.6")'
> check 0.8.6
+
+> 'set libraryDependencies := Seq("net.databinder" %% "dispatch-http" % "0.8.6")'
+> check 0.8.6
+> 'set dependencyOverrides := Set("net.databinder" %% "dispatch-http" % "0.8.7")'
+> check 0.8.7
@@ -0,0 +1,7 @@
+sbtBinaryVersion := "0.11.2"
+
+addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.0")
+
+resolvers += Classpaths.typesafeResolver
+
+dependencyOverrides := Set("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.1")
@@ -0,0 +1 @@
+> update

0 comments on commit 5fa93ca

Please sign in to comment.