# Example 39.1. A custom plugin - Examples Wrong

**URL:** <https://discuss.gradle.org/t/example-39-1-a-custom-plugin-examples-wrong/13557>\
**Category:** Bugs\
**Tags:** plugins\
**Created:** [January 6, 2016, 6:33pm UTC](https://discuss.gradle.org/t/example-39-1-a-custom-plugin-examples-wrong/13557 "2016-01-06T18:33:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcllings](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@jcllings](https://discuss.gradle.org/u/jcllings)\
**Post date:** [January 6, 2016, 6:33pm UTC](https://discuss.gradle.org/t/example-39-1-a-custom-plugin-examples-wrong/13557/1 "2016-01-06T18:33:02Z")

</div>

[https://docs.gradle.org/current/userguide/custom\_plugins.html](https://docs.gradle.org/current/userguide/custom_plugins.html)

Shouldn’t it be:

```
import org.gradle.api.Project
import org.gradle.api.Plugin

class GreetingPlugin implements Plugin<Project> {
    void apply(Project project) {
        project.task('hello') << {
            println "Hello from the GreetingPlugin"
        }
    }
}

```

If I have the “apply” in there I get an error to the effect that GreetingPlugin is defined twice. Includes:

Example 39.1. A custom plugin  
Example 39.2. A custom plugin extension  
Example 39.3. A custom plugin with configuration closure

Also “39.5.4. Writing tests for your plugin” which reads:

```
class GreetingPluginTest {
    @Test
    public void greeterPluginAddsGreetingTaskToProject() {
        Project project = ProjectBuilder.builder().build()
        project.pluginManager.apply 'org.samples.greeting'

        assertTrue(project.tasks.hello instanceof GreetingTask)
    }
}

```

Last line should probably have a test for GreetingPlugin not GreetingTask.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [January 6, 2016, 7:31pm UTC](https://discuss.gradle.org/t/example-39-1-a-custom-plugin-examples-wrong/13557/2 "2016-01-06T19:31:41Z")

</div>

> [@jcllings](#):
>
> If I have the “apply” in there I get an error to the effect that GreetingPlugin is defined twice. Includes:

The example assumes your are writing this in a build script so the plugin is defined and applied in the same place. Of course, if you were to use ‘buildSrc’ or a separate project you would do as you outlined above.

> [@jcllings](#):
>
> Last line should probably have a test for GreetingPlugin not GreetingTask.

I’m not sure what you mean. The behavior of the plugin is that it creates a task named ‘hello’ of type `GreetingTask`. This test case simply validates that such a task is created when the plugin is applied.

---

<div class="post-metadata">

**Author:** ![jcllings](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@jcllings](https://discuss.gradle.org/u/jcllings)\
**Post date:** [January 7, 2016, 9:06pm UTC](https://discuss.gradle.org/t/example-39-1-a-custom-plugin-examples-wrong/13557/3 "2016-01-07T21:06:43Z")

</div>

OK, that makes sense.
