dependency-check-gradle icon indicating copy to clipboard operation
dependency-check-gradle copied to clipboard

Allow passing Action<T> when configuring nested extensions

Open hakanai opened this issue 4 years ago • 3 comments

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.

hakanai avatar May 04 '20 06:05 hakanai

Thanks for the suggestion. We accept PRs.

jeremylong avatar May 04 '20 11:05 jeremylong

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.

hakanai avatar May 12 '20 23:05 hakanai

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
    })
}

ianbrandt avatar Jun 26 '23 17:06 ianbrandt