0

I am creating a specialized build task in my project that would require user input in STDIN which will let users select which version of hadoop,spark etc libraries will be used to build the application.

so far I have created a that task looks like the below.

lazy val build = SettingKey[Unit]("build", "build the app with all dependencies") in all // all is a project key

build := {
    println(s"input hadoop client version")
    val hadoop = scala.io.Source.fromInputStream(System.in).bufferedReader().readLine
    println(s"input hiveserver jdbc version")
    val hiveserver = scala.io.Source.fromInputStream(System.in).bufferedReader().readLine
    // bunch of code to customize the build
}

The problem with the above code is that the body of build task key is run whenever the project is initialized in sbt or whenever reload task is run. so whenever I open the project in sbt, it hangs waiting for me to enter the version inputs in the standard input. How the task be made such that its body is executed only when the task is run and not when the build is initialized

rogue-one
  • 11,259
  • 7
  • 53
  • 75
  • When running which command do you want to prompt user for input? `build` sounds unsuitable because it's run more often than you expect. – Samuel Oct 03 '16 at 03:23
  • @Samuel do you mean build is a predefined task in sbt. I am not able to find any such pre-defined task in sbt. I assume build is custom task – rogue-one Oct 03 '16 at 18:53

1 Answers1

0

I would consider defining a new custom task [http://www.scala-sbt.org/0.12.2/docs/Getting-Started/Custom-Settings.html#implementing-a-task] rather than extending build with blocking commands such as user input. As you experienced build is executed quite often. You could for example extend build to use predefined values, read from environment settings. And have a interactiveBuild task where you prompt the user, showing the defaults retrieved from the env vars. For more info about defining custom tasks check these out:

Community
  • 1
  • 1
Devis L.
  • 313
  • 2
  • 11
  • as per my code snippet build is indeed a new custom task. I dont think build is a pre-defined sbt task that I am extending. The environmental based approach is interesting and I will look into the links you have shared. – rogue-one Oct 03 '16 at 18:57