I'd like to add a configuration within a plugin at runtime and probably also register it at projectConfigurations
. Is there a possibility to manipulate the state in such a way? I assume this needs to be done in a command, and the solution is buried somewhere deep inside of the AttributeMap
, but I'm not sure how to approach that beast.
def addConfiguration = Command.single( "add-configuration" )( ( state, configuration ) => {
val extracted = Project extract state
val c = configurations.apply( configuration )
// Add c to the state ...
???
} )
Background
I'm working on a sbt-slick-codegen plugin, which has multi-database support as an essential feature. Now to configure databases in sbt, I took a very simple approach: everything is stuffed into a Map.
databases in SlickCodegen ++= Map(
"default" -> Database(
Authentication(
url = "jdbc:postgresql://localhost:5432/db",
username = Some( "db_user_123" ),
password = Some( "p@assw0rd" )
),
Driver(
jdbc = "org.postgresql.Driver",
slick = slick.driver.PostgresDriver,
user = Some( "com.example.MySlickProfile" )
),
container = "Tables",
generator = new SourceCodeGenerator( _ ),
identifier = Some( "com.example" ),
excludes = Seq( "play_evolutions" ),
cache = true
),
"user_db" -> Database( ... )
)
Now, this works, but defeats the purpose of sbt, is hard to setup, difficult to maintain and update. I'd instead prefer configuration to work like this:
container in Database := "MyDefaultName",
url in Database( "backup" ) := "jdbc:postgresql://localhost:5432/database",
cache in Database( "default" ) := false
And also this approach is working on the current development branch, but only for Database( x )
-configurations that are known at compile time, which leads to the next problem:
On top of that, I'm planning to add a module with PlayFramework support. The idea is to have a setting SettingKey[Seq[Config]]( "configurations" )
that accepts Typesafe Config
instances, reads the slick configurations from them and generates appropriate Database( x )
-configurations. But for this step I am out of ideas.