sbt-assembly
sbt-assembly copied to clipboard
Support to convert cross-versioned ModuleID to ModuleCoordinate
Resolve #403
Support to convert cross-versioned ModuleID to ModuleCoordinate.
Background
-
ShadePattern.inLibraryextension method provides an easy way to add sbt-librarymanagement'sModuleIDas jarjar-abrams'sModuleCoordinatetoShadeRule. - However, current conversion from
ModuleIDtoModuleCoordinatedoes not support for cross-versionedModuleID.
Consideration
- Should be completed on sbt-assembly plugin layer.
- This support should essentially be provided in sbt-assembly plugin, so it is not good to modify jarjar-abrams.
- Should not break current syntax.
- Introduce wrapper class
AssemblyShadeRuleforShadeRulewithout modifying jarjar-abrams. - Provide implicit conversion for compatibility.
- Introduce wrapper class
alternatively if you don't wan't for this PR to get published:
import com.eed3si9n.jarjarabrams
import sbt.librarymanagement.{CrossVersion, ScalaModuleInfo}
implicit class RichShadePattern(pattern: jarjarabrams.ShadePattern) {
def inLibraryWithScalaModuleInfo(scalaModuleInfo: Option[ScalaModuleInfo])(moduleIds: ModuleID*): jarjarabrams.ShadeRule = {
val moduleIdsWithCrossVersion =
moduleIds.map(module =>
(for {
sm <- scalaModuleInfo
f <- CrossVersion(module, scalaModuleInfo)
} yield module.withName(f(module.name))).getOrElse(module)
)
inLibraryBase(moduleIdsWithCrossVersion: _*)
}
private def inLibraryBase(moduleId: ModuleID*): jarjarabrams.ShadeRule =
pattern.inModuleCoordinates(
moduleId.toVector
.map(m => jarjarabrams.ModuleCoordinate(m.organization, m.name, m.revision)): _*
)
}
usage:
ShadeRule.rename("cats.kernel.**" -> s"new_cats.kernel.@1").inLibraryWithScalaModuleInfo(scalaModuleInfo.value)(
"org.typelevel" %% "spire" % "0.17.0"
)
Sorry about the delayed response. Given that I control Jar Jar Abrams as well, I feel like a better solution would be to capture whatever information we need to about ModuleID at Jar Jar Abrams level, if current ModuleCoordinate is insufficient. % vs %% for instance is expressed by crossVersion here - https://github.com/sbt/librarymanagement/blob/54011d5e74335bab229bc3f6532b6a1ca6d0d5cd/core/src/main/contraband-scala/sbt/librarymanagement/ModuleID.scala