Home > database >  What does create method do in gradlePlugin.plugins?
What does create method do in gradlePlugin.plugins?

Time:12-18

In the gradle doc: https://docs.gradle.org/current/userguide/custom_plugins.html#sec:custom_plugins_standalone_project

The code block is:

gradlePlugin {
    plugins {
        create("simplePlugin") {
            id = "org.example.greeting"
            implementationClass = "org.example.GreetingPlugin"
        }
    }
}

I noticed it calls create method. And I looked the source code. It says:

Creates a new item with the given name, adding it to this container, then configuring it with the given action.

What does it mean? Is it actually used anywhere? Or it can be any name does not really matter?

CodePudding user response:

gradlePlugin.plugins is a NamedDomainObjectContainer - which are used by Gradle to hold multiple objects, each with a name.

The documentation on plugin development goes into more detail on the usage of NamedDomainObjectContainers.

Sometimes you might want to expose a way for users to define multiple, named data objects of the same type.

[...]

It’s very common for a plugin to post-process the captured values within the plugin implementation e.g. to configure tasks.

Since the elements of a NamedDomainObjectContainer can be any type, there's no specific usage for one. Generally they are used to configure the Gradle project, for example creating specific tasks, configuring source code locations.

  • Related