sbt / sbt-assembly

Deploy über-JARs. Restart processes. (port of codahale/assembly-sbt)
MIT License
1.94k stars 223 forks source link

Support to convert cross-versioned ModuleID to ModuleCoordinate #500

Open cryeo opened 12 months ago

cryeo commented 12 months ago

Resolve #403

Support to convert cross-versioned ModuleID to ModuleCoordinate.

Background

Consideration

MasseGuillaume commented 7 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"
)
eed3si9n commented 7 months ago

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