scalasbtkind-projector

Clarifying cross version behavior in Scala


I wonder what is the difference between the two here:

addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.3" cross CrossVersion.full)

// if your project uses multiple Scala versions, use this for cross building
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.11.3" cross CrossVersion.full)

My understanding was that cross CrossVersion.full add the full Scala version to the library e.g.

kind-project_2.13.4:0.11.3

and that %% adds the Scala Binary version e.g.

kind-project_2.13:0.11.3

Hence I do not understand why we need cross CrossVersion.full with both % and %%. What's the difference?


Solution

  • I am pretty sure they are the same.

    From Overriding the publishing convention:

    crossVersion setting can override the publishing convention:

    • CrossVersion.disabled (no suffix)
    • CrossVersion.binary (_)
    • CrossVersion.full (_)

    The default is either CrossVersion.binary or CrossVersion.diabled depending on the value of crossPaths.

    From More about using cross-built libraries:

    These are equivalent:

    "a" %% "b" % "1.0"
    ("a" % "b" % "1.0").cross(CrossVersion.binary)
    

    So eventually all it matters is the value of crossVersion.

    In order to test the crossVersion, I created a simple task in my build.sbt:

    lazy val getVersion = taskKey[Unit]("A simple task")
    getVersion := {
      List(dep1, dep2, dep3, dep4).foreach { d =>
        val att = Seq(d.organization ,d.name ,d.revision ,d.configurations ,d.isChanging ,d.isTransitive ,d.isForce ,d.explicitArtifacts ,d.inclusions ,d.exclusions ,d.extraAttributes ,d.crossVersion ,d.branchName)
        println(att)
      }
    }
    lazy val dep1 = "org.typelevel" % "kind-projector" % "0.11.3" cross CrossVersion.full
    lazy val dep2 = "org.typelevel" %% "kind-projector" % "0.11.3" cross CrossVersion.full
    lazy val dep3 = "org.typelevel" % "kind-projector" % "0.11.3"
    lazy val dep4 = "org.typelevel" %% "kind-projector" % "0.11.3"
    

    The output of sbt getVersion is:

    List(org.typelevel, kind-projector, 0.11.3, None, false, true, false, Vector(), Vector(), Vector(), Map(), Full(, ), None)
    List(org.typelevel, kind-projector, 0.11.3, None, false, true, false, Vector(), Vector(), Vector(), Map(), Full(, ), None)
    List(org.typelevel, kind-projector, 0.11.3, None, false, true, false, Vector(), Vector(), Vector(), Map(), Disabled(), None)
    List(org.typelevel, kind-projector, 0.11.3, None, false, true, false, Vector(), Vector(), Vector(), Map(), Binary(, ), None)
    

    As we can see, all of the modules are equivalent, except for crossVersion, which in both dep1, and dep2 is Full(, ). Unlike the two others which are Disabled() and Binary(, ).