Open cryeo opened 12 months ago
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
Resolve #403
Support to convert cross-versioned
ModuleID
toModuleCoordinate
.Background
ShadePattern.inLibrary
extension method provides an easy way to add sbt-librarymanagement'sModuleID
as jarjar-abrams'sModuleCoordinate
toShadeRule
.ModuleID
toModuleCoordinate
does not support for cross-versionedModuleID
.Consideration
AssemblyShadeRule
forShadeRule
without modifying jarjar-abrams.