How to pass scalacOptions (Xelide-below) to sbt via command line

I am trying to call sbt assembly from the command line, passing it the scalac compiler flag in elides (elide-below 1).

I managed to get the flag working in build.sbt by adding this line to the build.sbt file

scalacOptions ++= Seq("-Xelide-below", "1")

And also it works fine when I run sbt and run the following:

$> sbt                                                                                                                        
$> set scalacOptions in ThisBuild ++=Seq("-Xelide-below", "0")

But I would like to know how to pass this when running sbt so that my CI jobs can use it for different build purposes (e.g. dev / test / prod).

+4
source share
1 answer

One way to pass the elite level as a command line parameter is to use system properties

scalacOptions ++= Seq("-Xelide-below", sys.props.getOrElse("elide.below", "0"))

sbt -Delide.below=20 assembly. , .

- test/prod.

lazy val elideLevel = settingKey[Int]("elide code below this level.")
elideLevel in Global := 0
scalacOptions ++= Seq("-Xelide-below", elideLevel.value.toString)
def assemblyCommand(name: String, level: Int) =
  Command.command(s"${name}Assembly") { s =>
    s"set elideLevel in Global := $level" ::
      "assembly" ::
      s"set elideLevel in Global := 0" ::
      s
  }
commands += assemblyCommand("test", 10)
commands += assemblyCommand("prod", 1000)

sbt testAssembly prodAssembly. , sbt-shell, , , testAssembly. sbt-shell , .

+4

Source: https://habr.com/ru/post/1623033/


All Articles