mirror of https://github.com/sbt/sbt.git
[2.x] Report eviction errors for Test dependencies (#8451)
Eviction warnings and errors were not reported for Test dependencies because `EvictionError` only checked the Compile configuration. This fix runs the eviction check for both Compile and Test configurations separately, with distinct error messages: - Compile: `found version conflict(s) in library dependencies` - Test: `found version conflict(s) in Test dependencies`
This commit is contained in:
parent
997ad9619a
commit
8c20401fb9
|
|
@ -1143,6 +1143,7 @@ lazy val lmCore = (project in file("lm-core"))
|
|||
},
|
||||
mimaSettings,
|
||||
mimaBinaryIssueFilters ++= Seq(
|
||||
exclude[DirectMissingMethodProblem]("sbt.librarymanagement.EvictionError.processEvictions"),
|
||||
),
|
||||
)
|
||||
.dependsOn(utilLogging, utilPosition, utilCache)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,27 @@ object EvictionError {
|
|||
assumedVersionSchemeJava: String,
|
||||
assumedEvictionErrorLevel: Level.Value,
|
||||
): EvictionError = {
|
||||
val options = EvictionWarningOptions.full
|
||||
apply(
|
||||
report,
|
||||
module,
|
||||
schemes,
|
||||
assumedVersionScheme,
|
||||
assumedVersionSchemeJava,
|
||||
assumedEvictionErrorLevel,
|
||||
Configurations.Compile,
|
||||
)
|
||||
}
|
||||
|
||||
def apply(
|
||||
report: UpdateReport,
|
||||
module: ModuleDescriptor,
|
||||
schemes: Seq[ModuleID],
|
||||
assumedVersionScheme: String,
|
||||
assumedVersionSchemeJava: String,
|
||||
assumedEvictionErrorLevel: Level.Value,
|
||||
configuration: ConfigRef,
|
||||
): EvictionError = {
|
||||
val options = EvictionWarningOptions.full.withConfigurations(Vector(configuration))
|
||||
val evictions = EvictionWarning.buildEvictions(options, report)
|
||||
processEvictions(
|
||||
module,
|
||||
|
|
@ -33,6 +53,7 @@ object EvictionError {
|
|||
assumedVersionScheme,
|
||||
assumedVersionSchemeJava,
|
||||
assumedEvictionErrorLevel,
|
||||
configuration,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -44,6 +65,7 @@ object EvictionError {
|
|||
assumedVersionScheme: String,
|
||||
assumedVersionSchemeJava: String,
|
||||
assumedEvictionErrorLevel: Level.Value,
|
||||
configuration: ConfigRef = Configurations.Compile,
|
||||
): EvictionError = {
|
||||
val directDependencies = module.directDependencies
|
||||
val pairs = reports map { detail =>
|
||||
|
|
@ -133,6 +155,7 @@ object EvictionError {
|
|||
new EvictionError(
|
||||
incompatibleEvictions.toList,
|
||||
assumedIncompatibleEvictions.toList,
|
||||
configuration,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +167,7 @@ object EvictionError {
|
|||
final class EvictionError private[sbt] (
|
||||
val incompatibleEvictions: Seq[(EvictionPair, String)],
|
||||
val assumedIncompatibleEvictions: Seq[(EvictionPair, String)],
|
||||
val configuration: ConfigRef = Configurations.Compile,
|
||||
) {
|
||||
def run(): Unit =
|
||||
if (incompatibleEvictions.nonEmpty) {
|
||||
|
|
@ -154,9 +178,13 @@ final class EvictionError private[sbt] (
|
|||
|
||||
def toAssumedLines: List[String] = toLines(assumedIncompatibleEvictions, true)
|
||||
|
||||
private def configurationLabel: String =
|
||||
if (configuration.name == Configurations.Compile.name) "library dependencies"
|
||||
else s"${configuration.name.capitalize} dependencies"
|
||||
|
||||
def toLines(evictions: Seq[(EvictionPair, String)], assumed: Boolean): List[String] = {
|
||||
val out: mutable.ListBuffer[String] = mutable.ListBuffer()
|
||||
out += "found version conflict(s) in library dependencies; some are suspected to be binary incompatible:"
|
||||
out += s"found version conflict(s) in $configurationLabel; some are suspected to be binary incompatible:"
|
||||
out += ""
|
||||
evictions.foreach({ (a, scheme) =>
|
||||
val seen: mutable.Set[ModuleID] = mutable.Set()
|
||||
|
|
|
|||
|
|
@ -68,19 +68,29 @@ private[sbt] object LibraryManagement {
|
|||
val report1 = transform(report)
|
||||
|
||||
// Warn of any eviction and compatibility warnings
|
||||
val evictionError = EvictionError(
|
||||
val evictionErrorCompile = EvictionError(
|
||||
report1,
|
||||
module,
|
||||
versionSchemeOverrides,
|
||||
assumedVersionScheme,
|
||||
assumedVersionSchemeJava,
|
||||
assumedEvictionErrorLevel
|
||||
assumedEvictionErrorLevel,
|
||||
Configurations.Compile,
|
||||
)
|
||||
val evictionErrorTest = EvictionError(
|
||||
report1,
|
||||
module,
|
||||
versionSchemeOverrides,
|
||||
assumedVersionScheme,
|
||||
assumedVersionSchemeJava,
|
||||
assumedEvictionErrorLevel,
|
||||
Configurations.Test,
|
||||
)
|
||||
def extraLines = List(
|
||||
"",
|
||||
"this can be overridden using libraryDependencySchemes or evictionErrorLevel"
|
||||
)
|
||||
val errorLines: Seq[String] =
|
||||
def errorLinesFor(evictionError: EvictionError): Seq[String] =
|
||||
(if (
|
||||
evictionError.incompatibleEvictions.isEmpty
|
||||
|| evictionLevel != Level.Error
|
||||
|
|
@ -91,13 +101,20 @@ private[sbt] object LibraryManagement {
|
|||
|| assumedEvictionErrorLevel != Level.Error
|
||||
) Nil
|
||||
else evictionError.toAssumedLines)
|
||||
val errorLines: Seq[String] =
|
||||
errorLinesFor(evictionErrorCompile) ++ errorLinesFor(evictionErrorTest)
|
||||
if (errorLines.nonEmpty) sys.error((errorLines ++ extraLines).mkString(System.lineSeparator))
|
||||
else {
|
||||
if (evictionError.incompatibleEvictions.isEmpty) ()
|
||||
else evictionError.lines.foreach(log.log(evictionLevel, _: String))
|
||||
if (evictionErrorCompile.incompatibleEvictions.isEmpty) ()
|
||||
else evictionErrorCompile.lines.foreach(log.log(evictionLevel, _: String))
|
||||
if (evictionErrorCompile.assumedIncompatibleEvictions.isEmpty) ()
|
||||
else
|
||||
evictionErrorCompile.toAssumedLines.foreach(log.log(assumedEvictionErrorLevel, _: String))
|
||||
|
||||
if (evictionError.assumedIncompatibleEvictions.isEmpty) ()
|
||||
else evictionError.toAssumedLines.foreach(log.log(assumedEvictionErrorLevel, _: String))
|
||||
if (evictionErrorTest.incompatibleEvictions.isEmpty) ()
|
||||
else evictionErrorTest.lines.foreach(log.log(evictionLevel, _: String))
|
||||
if (evictionErrorTest.assumedIncompatibleEvictions.isEmpty) ()
|
||||
else evictionErrorTest.toAssumedLines.foreach(log.log(assumedEvictionErrorLevel, _: String))
|
||||
}
|
||||
CompatibilityWarning.run(compatWarning, module, mavenStyle, log)
|
||||
val report2 = transformDetails(report1, includeCallers, includeDetails)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
// https://github.com/sbt/sbt/issues/8410
|
||||
scalaVersion := "3.3.4"
|
||||
libraryDependencies ++= Seq(
|
||||
"org.typelevel" %% "weaver-cats" % "0.8.4" % Test,
|
||||
"com.siriusxm" %% "snapshot4s-weaver" % "0.1.5" % Test,
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
-> update
|
||||
Loading…
Reference in New Issue