dependency-check-gradle
dependency-check-gradle copied to clipboard
Allow passing Action<T> when configuring nested extensions
If you're using configuring the plugin using Java code, you really want to write things like this:
dependencyCheck.cve(cve -> {
cve.setUrlBase(...);
});
But currently you can't, because the cve
method only takes Closure
, making it only callable from Groovy.
All methods to configure extensions should have overloads taking Action<T>
. This might affect Kotlin build scripts too but I haven't found out yet because other things break those anyway.
Thanks for the suggestion. We accept PRs.
I'm having a look. Is there a tidier way to do this?
/**
* Allows programmatic configuration of the analyzer extension
* @param configAction the action to configure the analyzers extension
* @return the analyzers extension
*/
def analyzers(Action<? super AnalyzerExtension> configAction) {
configAction.execute(analyzers)
return analyzers
}
The existing ones using Closure
are using project.configure
but the only overloads taking Action
take and return a collection of things to configure, which is awkward for returning a single object.
This might affect Kotlin build scripts too but I haven't found out yet...
For the Kotlin DSL I have to use closureOf<T> { }
, e.g.:
dependencyCheck {
analyzers(closureOf<AnalyzerExtension> {
assemblyEnabled = false
})
}