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

scala – 更改当前sbt任务范围中的变量

发布时间:2020-12-16 19:15:15 所属栏目:安全 来源:网络整理
导读:这会编译,但不会将 scalacOptions添加到编译任务中.这样做的正确方法是什么? compileWall in ThisBuild := Def.task { scalacOptions += "-Xfatal-warnings" (compile in Compile).value}.value 解决方法 SBT设置在运行时是不可变的,因此我们无法更新自定义
这会编译,但不会将 scalacOptions添加到编译任务中.这样做的正确方法是什么?

compileWall in ThisBuild := Def.task {
  scalacOptions += "-Xfatal-warnings"
  (compile in Compile).value
}.value

解决方法

SBT设置在运行时是不可变的,因此我们无法更新自定义任务中的scalacOptions.

http://www.scala-sbt.org/0.13/docs/Full-Def.html#Reminder%3A+it%E2%80%99s+all+immutable

但有一种方法可以通过创建自定义配置并在此配置中绑定scalacOptions来实现自定义任务中的更改scalacOptions,如:

lazy val MyCompile = config("MyCompile") extend Compile // customize config: MyCompile
configs(MyCompile) //configs 
inConfig(MyCompile)(Defaults.configTasks) //inConfig and append the Defaults.configTasks

val compileWall = taskKey[Unit]("compileWall")

compileWall in ThisBuild := {
  (compile in MyCompile).value
}

scalacOptions in MyCompile := Seq("-Xfatal-warnings") // bind the scalacOptions in customize config.

(编辑:李大同)

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

    推荐文章
      热点阅读