Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing Action<T> when configuring nested extensions #187

Open
hakanai opened this issue May 4, 2020 · 3 comments
Open

Allow passing Action<T> when configuring nested extensions #187

hakanai opened this issue May 4, 2020 · 3 comments

Comments

@hakanai
Copy link
Contributor

hakanai commented May 4, 2020

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.

@jeremylong
Copy link
Collaborator

Thanks for the suggestion. We accept PRs.

@hakanai
Copy link
Contributor Author

hakanai commented May 12, 2020

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.

@ianbrandt
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants