阐明 Scala 中的跨版本行为
Clarifying cross version behavior in Scala
我想知道这两者有什么区别:
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)
我的理解是 cross CrossVersion.full
将完整的 Scala 版本添加到库中,例如
kind-project_2.13.4:0.11.3
并且 %%
添加了 Scala 二进制版本,例如
kind-project_2.13:0.11.3
因此我不明白为什么 %
和 %%
都需要 cross CrossVersion.full
。有什么区别?
我很确定它们是一样的。
来自 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.
来自 More about using cross-built libraries:
These are equivalent:
"a" %% "b" % "1.0"
("a" % "b" % "1.0").cross(CrossVersion.binary)
所以最终重要的是 crossVersion
.
的值
为了测试 crossVersion
,我在 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"
sbt getVersion
的输出是:
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)
正如我们所见,所有模块都是等价的,除了 crossVersion
,它在 dep1
和 dep2
中都是 Full(, )
。不像其他两个 Disabled()
和 Binary(, )
.
我想知道这两者有什么区别:
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)
我的理解是 cross CrossVersion.full
将完整的 Scala 版本添加到库中,例如
kind-project_2.13.4:0.11.3
并且 %%
添加了 Scala 二进制版本,例如
kind-project_2.13:0.11.3
因此我不明白为什么 %
和 %%
都需要 cross CrossVersion.full
。有什么区别?
我很确定它们是一样的。
来自 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
orCrossVersion.diabled
depending on the value of crossPaths.
来自 More about using cross-built libraries:
These are equivalent:
"a" %% "b" % "1.0" ("a" % "b" % "1.0").cross(CrossVersion.binary)
所以最终重要的是 crossVersion
.
为了测试 crossVersion
,我在 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"
sbt getVersion
的输出是:
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)
正如我们所见,所有模块都是等价的,除了 crossVersion
,它在 dep1
和 dep2
中都是 Full(, )
。不像其他两个 Disabled()
和 Binary(, )
.