-
Notifications
You must be signed in to change notification settings - Fork 103
Description
This is another approach to enhance the config (similar to #10).
I would suggest a "default config" object which contains all possible config keys and defaults.
Modules must have a method to add to this default config. Adding the same "path" twice is an error but it should be possible to check for an existing path (so two modules can cooperate and still be optional).
This way, modules don't need code like
CFG.'maven.tool_version' ?: 'Maven 3'
because 'Maven 3' will be the default value. Reading unknown keys should throw an exception (-> typo in library)
The step which parses the project's config options from the should throw exceptions for unknown keys/paths to catch typos.
After merging the project and default config, the result should be logged in Jenkins to allow to find mistakes.
I'm also not fond of the CFG.'xxx.yyy'
syntax. With the default config as path supplier, it should be possible to implement a nested config using nested Map
s which would then allow to pass inner maps around so the code would become independent of the path.
In my builds, I'm calling Maven several times (build with unit tests, site, deploy without tests). Using nested configs, I can create a shared Maven config (default JDK & Maven tool) but I can also tweak the options passed to each individual Maven invocation like additional profiles to activate or system properties. As an example, I can:
config {
build {
addAfter 'install', 'foo'
}
}
to get mvn [...] clean install foo sonar:sonar
as command line or I can
config {
maven {
property('foo', params['foo'])
}
}
to add -Dfoo=[...]
to every Maven invocation.
My current code depends on a hand-written config builder class for each nested config object. That way, I can support things like addAfter()
. I'm looking into ways to change this so modules can easily define their default config.