Compiling a Scala File

Good morning,

Is there a way how you could run an 'sbt compile' from a Scala File i.e. from a testFile.scala for example ?

Just to clarify, instead of compiling the directory from terminal using 'sbt compile', is there any way I could produce the same command however during an execution of a file please ?

Thanks a lot and good day :slight_smile:

Well you could always just call SBT as an external command, see scala.sys.process.ProcessBuilder for that.

What is it you are trying to achieve? If the Scala file you want to run sbt compile from is one of the same sbt project’s files, note that you’ll still have to restart the program to get the changes to the classes.

If you’re writing something that takes other Scala files as input, it is possible to call the Scala compiler programmatically (the API is in the package), but I don’t have experience with that. Maybe look into how REPLs like ammonite compile their input?

1 Like

Thanks a lot for your help.

ProcessBuilder will suffice :slight_smile: