简体   繁体   English

阐明 Scala 中的跨版本行为

[英]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 eg我的理解是cross CrossVersion.full将完整的 Scala 版本添加到库中,例如

kind-project_2.13.4:0.11.3

and that %% adds the Scala Binary version eg并且%%添加了 Scala 二进制版本,例如

kind-project_2.13:0.11.3

Hence I do not understand why we need cross CrossVersion.full with both % and %% .因此,我不明白为什么我们需要cross CrossVersion.full%%% What's the difference?有什么不同?

I am pretty sure they are the same.我很确定它们是一样的。

From Overriding the publishing convention :覆盖发布约定

crossVersion setting can override the publishing convention: crossVersion 设置可以覆盖发布约定:

  • CrossVersion.disabled (no suffix) CrossVersion.disabled (无后缀)
  • CrossVersion.binary (_) CrossVersion.binary (_)
  • CrossVersion.full (_) CrossVersion.full (_)

The default is either CrossVersion.binary or CrossVersion.diabled depending on the value of crossPaths.默认值为CrossVersion.binaryCrossVersion.diabled ,具体取决于 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 .所以最终重要的是crossVersion的值。

In order to test the crossVersion , I created a simple task in my build.sbt :为了测试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"

The output of sbt getVersion is: sbt getVersion的 output 为:

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(, ) .正如我们所看到的,所有模块都是等价的,除了crossVersion ,它在dep1dep2中都是Full(, ) Unlike the two others which are Disabled() and Binary(, ) .与其他两个Disabled()Binary(, )不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Scala 2 Scala 3 项目中的工件:冲突的跨版本后缀 - Scala 2 artifact in Scala 3 project: conflicting cross-version suffixes SBT跨建筑 - 为不同的scala版本选择不同的库版本 - SBT cross building - choosing a different library version for different scala version .jar文件与不兼容的Scala版本(2.10)交叉编译 - .jar files cross-compiled with an incompatible version of Scala (2.10) spark 构建路径与 Scala (2.11.0) 的不兼容版本交叉编译 - spark build path is cross-compiled with an incompatible version of Scala (2.11.0) 使用不兼容的Scala版本(2.9.2)交叉编译.jar文件 - .jar files cross-compiled with an incompatible version of Scala (2.9.2) 跨版本的Scala API适用于各种Spark版本 - Cross-build scala API for various spark version SBT中关于scala-xml的交叉版本后缀 - Cross-version suffixes in SBT with regards to scala-xml 使用Build.scala进行交叉编译时,如何为每个Scala版本设置不同的scalacOptions? - How to set different scalacOptions per Scala version when cross-compiling using Build.scala? 如何从具有特定项目的交叉构建的SBT多项目中删除Scala版本 - How to remove scala version from an sbt multi project with cross build on a particular project 交叉版本后缀冲突:com.fasterxml.jackson.module:jackson-module-scala - Conflicting cross-version suffixes in: com.fasterxml.jackson.module:jackson-module-scala
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM