mirror of https://github.com/sbt/sbt.git
warn when there is an sbt version conflict. fixes #80
This commit is contained in:
parent
15427d32b3
commit
1d792c3601
|
|
@ -0,0 +1,20 @@
|
|||
package sbt
|
||||
|
||||
import DependencyFilter._
|
||||
|
||||
final case class ConflictWarning(filter: ModuleFilter, group: ModuleID => String, level: Level.Value, failOnConflict: Boolean)
|
||||
object ConflictWarning
|
||||
{
|
||||
def default: ConflictWarning = ConflictWarning( moduleFilter(organization = GlobFilter("org.scala-tools.sbt") | GlobFilter("org.scala-lang")), (_: ModuleID).organization, Level.Warn, false)
|
||||
|
||||
def apply(config: ConflictWarning, report: UpdateReport, log: Logger)
|
||||
{
|
||||
val conflicts = IvyActions.groupedConflicts(config.filter, config.group)(report)
|
||||
if(!conflicts.isEmpty)
|
||||
log.log(config.level, "Potentially incompatible versions specified:")
|
||||
for( (label, versions) <- conflicts )
|
||||
log.log(config.level, " " + label + ": " + versions.mkString(", "))
|
||||
if(config.failOnConflict && !conflicts.isEmpty)
|
||||
error("Conflicts in " + conflicts.map(_._1).mkString )
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ object DependencyFilter extends DependencyFilterExtra
|
|||
implicit def fnToModuleFilter(f: ModuleID => Boolean): ModuleFilter = new ModuleFilter { def apply(m: ModuleID) = f(m) }
|
||||
implicit def fnToArtifactFilter(f: Artifact => Boolean): ArtifactFilter = new ArtifactFilter { def apply(m: Artifact) = f(m) }
|
||||
implicit def fnToConfigurationFilter(f: String => Boolean): ConfigurationFilter = new ConfigurationFilter { def apply(c: String) = f(c) }
|
||||
implicit def subDepFilterToFn[Arg](f: SubDepFilter[Arg, _]): Arg => Boolean = f apply _
|
||||
}
|
||||
trait DependencyFilter
|
||||
{
|
||||
|
|
|
|||
|
|
@ -131,6 +131,18 @@ object IvyActions
|
|||
}
|
||||
}
|
||||
|
||||
def groupedConflicts[T](moduleFilter: ModuleFilter, grouping: ModuleID => T)(report: UpdateReport): Map[T, Set[String]] =
|
||||
report.configurations.flatMap { confReport =>
|
||||
val evicted = confReport.evicted.filter(moduleFilter)
|
||||
val evictedSet = evicted.map( m => (m.organization, m.name) ).toSet
|
||||
val conflicted = confReport.allModules.filter( mod => evictedSet( (mod.organization, mod.name) ) )
|
||||
grouped(grouping)(conflicted ++ evicted)
|
||||
} toMap;
|
||||
|
||||
def grouped[T](grouping: ModuleID => T)(mods: Seq[ModuleID]): Map[T, Set[String]] =
|
||||
mods groupBy(grouping) mapValues(_.map(_.revision).toSet)
|
||||
|
||||
|
||||
def transitiveScratch(ivySbt: IvySbt, label: String, config: GetClassifiersConfiguration, log: Logger): UpdateReport =
|
||||
{
|
||||
import config.{configuration => c, id, ivyScala, modules => deps}
|
||||
|
|
|
|||
|
|
@ -576,6 +576,7 @@ object Classpaths
|
|||
publishLocal <<= publishTask(publishLocalConfiguration, deliverLocal)
|
||||
)
|
||||
val baseSettings: Seq[Setting[_]] = Seq(
|
||||
conflictWarning in GlobalScope := ConflictWarning.default,
|
||||
unmanagedBase <<= baseDirectory / "lib",
|
||||
normalizedName <<= name(StringUtilities.normalize),
|
||||
organization <<= organization or normalizedName.identity,
|
||||
|
|
@ -644,6 +645,7 @@ object Classpaths
|
|||
update <<= (ivyModule, thisProjectRef, updateConfiguration, cacheDirectory, scalaInstance, streams) map { (module, ref, config, cacheDirectory, si, s) =>
|
||||
cachedUpdate(cacheDirectory / "update", Project.display(ref), module, config, Some(si), s.log)
|
||||
},
|
||||
update <<= (conflictWarning, update, streams) map { (config, report, s) => ConflictWarning(config, report, s.log); report },
|
||||
transitiveClassifiers in GlobalScope :== Seq(SourceClassifier, DocClassifier),
|
||||
updateClassifiers <<= (ivySbt, projectID, update, transitiveClassifiers in updateClassifiers, updateConfiguration, ivyScala, target in LocalRootProject, appConfiguration, streams) map { (is, pid, up, classifiers, c, ivyScala, out, app, s) =>
|
||||
withExcludes(out, classifiers, lock(app)) { excludes =>
|
||||
|
|
|
|||
|
|
@ -255,6 +255,7 @@ object Keys
|
|||
val packagedArtifact = TaskKey[(Artifact, File)]("packaged-artifact", "Generates a packaged artifact, returning the Artifact and the produced File.")
|
||||
val checksums = SettingKey[Seq[String]]("checksums", "The list of checksums to generate and to verify for dependencies.")
|
||||
|
||||
val conflictWarning = SettingKey[ConflictWarning]("conflict-warning", "Configures warnings for conflicts in dependency management.")
|
||||
val autoScalaLibrary = SettingKey[Boolean]("auto-scala-library", "Adds a dependency on scala-library if true.")
|
||||
val sbtResolver = SettingKey[Resolver]("sbt-resolver", "Provides a resolver for obtaining sbt as a dependency.")
|
||||
val sbtDependency = SettingKey[ModuleID]("sbt-dependency", "Provides a definition for declaring the current version of sbt.")
|
||||
|
|
|
|||
Loading…
Reference in New Issue