Is there a programmatic equivalent of using the model block in a build script?


(awilkinson) #1

I’m the developer of a dependency management plugin that can automatically add the configured dependency management to the pom that’s generated by the maven-publish plugin.

A user’s reported a problem that can be solved by wrapping some logic in a model {} block. This lead to me looking into whether or not it was possible for the plugin to do this for the user.

There’s some code in my plugin that does this:

project.plugins.withType(MavenPublishPlugin) {
    project.extensions.configure(PublishingExtension, new ClosureBackedAction({
        publications.withType(MavenPublication).all { publication ->
            configurePom(publication.pom, extension.pomConfigurer)
        }
    }))
}

My suspicion is that I could avoid the problem the user’s seeing if some or all of the above was wrapped in a model {} block. Looking at Gradle’s source, model only appear to be exposed via internal API and across the various versions comments on the method on the Project implementation say things like “Not part of the public API” and “Longer term it will not be available via Project, but be only available in a build script”.

Is there an API that a plugin can use that’s functionally equivalent to model{ … } in a build script?