Conditional scalacOptions with SBT

前端 未结 2 711
囚心锁ツ
囚心锁ツ 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:44

    When cross-building, scalaVersion reflects the version your project is currently built against. So depending on scalaVersion should do the trick:

    val scalaVersionRegex = "(\\d+)\\.(\\d+).*".r
    ...
    scalacOptions <++= scalaVersion { sv =>
      sv match {
        case scalaVersionRegex(major, minor) if major.toInt > 2 || (major == "2" && minor.toInt >= 10) =>
          Seq( "-deprecation", "-unchecked", "-feature" )
        case _ => Seq( "-deprecation", "-unchecked" )
    }
    

提交回复
热议问题