Where should local settings (per user, and not ver

2019-06-25 09:29发布

问题:

My application which is built using SBT requires particular settings that are specific to the host system (and may not even have sensible defaults). In my particular case I'm talking about the location of a piece of third-party software with dependent libraries required for the build (although there are plenty of other use cases for this). These settings should not be version-controlled, so they can't go into build.sbt or project/build.scala which should usually be in a VCS and applicable to all checkouts of the project.

In older versions of SBT (way back at 0.7.7) it was possible to define properties with defaults which could be set by the user in a file build.properties (this code still exists in the SBT source, incidentally, but it doesn't seem to be usable). That would do the job for me (despite the lack of strong typing) but is no longer an option. I'm wondering what the more modern alternative for this presumably common task is.

回答1:

It took surprisingly to work this out, but that answer is very straightforward once you know. Buried in the "Best Practices" section of the SBT documentation (this seems a slightly strange spot for it) is a section on "Local settings":

Put settings in a .sbt file in a project that isn't checked into version control, such as /local.sbt. sbt combines the settings from multiple .sbt files, so you can still have the standard /build.sbt and check that into version control.

Simple! You'll first need to add any custom user-settable settings to your project of course. For that, check out this SO answer (the original question is about plugins, but the answer there works fine for just a single project) which is a very helpful addition to the SBT documentation on the subject which is not quite as clear as it could be IMO.