加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在SBT 0.13中,scalaVersion是否仍然控制用于编译,运行和测试的sc

发布时间:2020-12-16 08:57:00 所属栏目:安全 来源:网络整理
导读:当我们将构建从12.4升级到13.1时,我观察到虽然构建指定了 scalaVersion:=“2.10.2”,但是生成的存档(通过sbt-pack插件创建)包含scala-library-2.10.3.jar.快速检查确认12.4版本包含scala-library-2.10.2.jar. 似乎sbt 0.13包含了将scala库视为正常依赖关系
当我们将构建从12.4升级到13.1时,我观察到虽然构建指定了 scalaVersion:=“2.10.2”,但是生成的存档(通过sbt-pack插件创建)包含scala-library-2.10.3.jar.快速检查确认12.4版本包含scala-library-2.10.2.jar.

似乎sbt 0.13包含了将scala库视为正常依赖关系的更改,结果是如果项目依赖项是使用稍后的2.10.x版本的scala构建的,则该传递依赖关系将“赢得”常春藤依赖项解析冲突解决方案,编译,测试和运行类路径将包含更高版本的scala库.

这是期望的行为,还是sbt 0.13中的错误?

如果是所需的行为,那么这是否意味着我必须使用机制来“强制/覆盖”冲突解决方案以使用我想要的scala库版本? (如果是这样,scalaVersion配置设置似乎有点无意义….)

这是一个非常极小的测试用例来说明行为:

test-proj/
  build.sbt
  project/
    build.properties

build.sbt:

scalaVersion := "2.10.2"
//scalaVersion := "2.10.3"

libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.0"
//libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.2.4"

build.properties:

sbt.version=0.13.1

Akka 2.2.4是针对scala 2.10.2构建的,因此启动sbt并运行“update”,“show update”,“show compile:dependencyClasspath”,“show test:dependencyClasspath”和“show runtime:dependencyClasspath”都显示scala -library 2.10.2在类路径上.

切换到针对scala 2.10.3构建的Akka 2.3.0,导致scala-library 2.10.3出现在所有类路径上,“show update”清楚地显示2.10.2被Ivy的冲突解决方案驱逐.

有趣的是(并且不一致),在两种情况下(通过sbt控制台命令)进入REPL会导致使用scala 2.10.2.

根据docs,在0.13

The scalaVersion configures the version of Scala used for compilation. By default,sbt also adds a dependency on the Scala library with this version.

基于此,我希望上面的编译类路径在两种情况下都包含2.10.2.

但是,the release notes for 0.13说

Scala dependencies (like scala-library and scala-compiler) are now resolved via the normal update task

这至少解释了观察到的行为.

解决方法

sbt 0.13.0更改

你写了:

It appears that sbt 0.13 included a change to treat the scala libraries as normal dependencies,with the consequence that if a project dependency was built with a later 2.10.x version of scala then that transitive dependency will “win” the ivy dependency resolution conflict resolution,and the compile,test and run classpaths will contain the later version of scala libraries.

sbt 0.13.0这个问题的变化有些矛盾. Features,fixes,changes with compatibility implications节说:

  • sbt no longer overrides the Scala version in dependencies. This allows independent configurations to depend on different Scala versions and treats Scala dependencies other than scala-library as normal dependencies. However,it can result in resolved versions other than scalaVersion for those other Scala libraries.

Resolving Scala dependencies节说:

Scala dependencies (like scala-library and scala-compiler) are now resolved via the normal update task.

(Eugene强调的重点)所以快速回答你的“这是期望的行为,还是0.13中的错误?”正如你已经回答的那样:在sbt 0.13.x中,这种行为似乎是有意的. Akka 2.3.0依赖于scala-library 2.10.3,而Ivy已经驱逐了scala-library 2.10.2,转而支持2.10.3.

dependencyOverrides

要解决此问题,您可以使用dependencyOverrides设置,如下所示:

dependencyOverrides += "org.scala-lang" % "scala-library" % scalaVersion.value

之前:

sbt-so-22551430> show fullClasspath
[info] List(... Attributed(/Users/xxx/.sbt/0.13/boot/scala-2.10.3/lib/scala-library.jar) ...)

后:

sbt-so-22551430> show fullClasspath
[info] List(... Attributed(/Users/xxx/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.10.2.jar) ...)

这种行为是否可取?

你的问题不是这是否是设计,而是如果这是可取的.我认为当前的行为是非常令人惊讶的,并且sbt至少应该改进通知构建用户这种行为.并且可能将其默认的Ivy冲突管理策略更改为强制()scalaVersion中指定的版本.以下是我创建的两个GitHub问题:

> shell should display all evicted libraries on start up #1200
> provide some means of forcing scala-library version to scalaVersion #1201

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读