# Need advice creating a plugin

**URL:** <https://discuss.gradle.org/t/need-advice-creating-a-plugin/23324>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [July 17, 2017, 10:10am UTC](https://discuss.gradle.org/t/need-advice-creating-a-plugin/23324 "2017-07-17T10:10:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![msouthall](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@msouthall](https://discuss.gradle.org/u/msouthall)\
**Post date:** [July 17, 2017, 10:10am UTC](https://discuss.gradle.org/t/need-advice-creating-a-plugin/23324/1 "2017-07-17T10:10:27Z")

</div>

Hi all,

So I need some advice on constructing a gradle build / plugin. I have a huge project I need to integrate some tasks into so it can be run in a CI environment and also deploy to a live production server.

Currently I have these tasks defined in a build.gradle file with a bunch of methods to do various things but this is getting messy and there is still a lot more to add.

I have decided to solve this by making a custom plugin which will do a lot of the work but need some advice on how to construct it.

I need to have a bunch of tasks which some rely on others.

The tasks I need to set out are:

1. Deploy
2. Build
3. Change values in a .properties file

The tasks need to rely on each other in that order but also have the ability to be run separately. I also need a parameter passed to each task my plan is to use @Option to do this, is this recommended? (any other way?)

The full process calling Deploy should do the following…

Deploy \<\> Build \<\> Change Values

How should this be setup, should I use build.dependsOn changeValues?

Also one other quick question, how do I make a gradle plugin call the “build” task (I think this is part of the Java plugin?) when I added “taskX.dependsOn build” it said that it couldn’t find the “build” task?

---

<div class="post-metadata">

**Author:** ![bmuschko](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko/32/5458_2.png) [@bmuschko](https://discuss.gradle.org/u/bmuschko)\
**Post date:** [July 17, 2017, 12:15pm UTC](https://discuss.gradle.org/t/need-advice-creating-a-plugin/23324/2 "2017-07-17T12:15:46Z")

</div>

> The tasks need to rely on each other in that order but also have the ability to be run separately.

That’s a typical use case for `mustRunAfter` instead of `dependsOn`.

> I also need a parameter passed to each task my plan is to use `@Option` to do this, is this recommended?

The annotation is currently an internal API. If you feel comfortable we using it then it’s a valid option. In the long run we’ll want to make it a public API: [Public API for defining and parsing custom command line options for tasks · Issue #2402 · gradle/gradle · GitHub](https://github.com/gradle/gradle/issues/2402).

> Also one other quick question, how do I make a gradle plugin call the “build” task (I think this is part of the Java plugin?)

It’s being added by the `JavaBasePlugin`. The `JavaPlugin` internally applies the `JavaBasePlugin`. You are relying on the `build` task then you can apply the `JavaBasePlugin` in your plugin.

Generally speaking I’d recommending reading the following topical guides on plugin development:

- [Redirecting to https://docs.gradle.org/current/userguide/designing\_gradle\_plugins.html](https://guides.gradle.org/designing-gradle-plugins/)
- [Redirecting to https://docs.gradle.org/current/userguide/implementing\_gradle\_plugins.html](https://guides.gradle.org/implementing-gradle-plugins/)

---

<div class="post-metadata">

**Author:** ![msouthall](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@msouthall](https://discuss.gradle.org/u/msouthall)\
**Post date:** [July 17, 2017, 1:08pm UTC](https://discuss.gradle.org/t/need-advice-creating-a-plugin/23324/3 "2017-07-17T13:08:41Z")

</div>

Thanks that helped.

Issue I am having now is the calling build, it seems to call build on buildSrc project and not the parent project?  
e.g

project.task(“someTask”) {  
finalizedBy “:build”  
}

---

<div class="post-metadata">

**Author:** ![bmuschko](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko/32/5458_2.png) [@bmuschko](https://discuss.gradle.org/u/bmuschko)\
**Post date:** [July 17, 2017, 1:35pm UTC](https://discuss.gradle.org/t/need-advice-creating-a-plugin/23324/4 "2017-07-17T13:35:17Z")

</div>

Please provide a minimalistic project on GitHub that reproduces the issue. I’d need to see the code.
