Conditional scalacOptions with SBT

前端 未结 2 814
囚心锁ツ
囚心锁ツ 2021-01-12 17:13

I am using a project with cross-build for Scala 2.8, 2.9 and (hopefully) 2.10, using SBT. I would like to add the -feature option when compiling with 2.10 only.

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 17:51

    I found this was quick and concise way of doing it:

    scalaVersion := "2.10.0"
    
    crossScalaVersions := "2.9.2" :: "2.10.0" :: Nil
    
    scalacOptions <<= scalaVersion map { v: String =>
      val default = "-deprecation" :: "-unchecked" :: Nil
      if (v.startsWith("2.9.")) default else default :+ "-feature"            
    }
    

提交回复
热议问题