What is a simple way to define a string constant to be the contents of a file at compile-time (in Scala)?
问题 I would like to define a Scala val to be a String whose value is the entire contents of a text file, as read at compile time . So, after compilation, this should just behave as a string constant. I have the feeling that this should be simple with, e.g., Scala macros, but so far I couldn't work out how to get the String value out simply. 回答1: You could make an sbt source generation task that executes at compile time; here's a simple example copied from those docs. It wouldn't be hard to extend