# Reference project directory from Kotlin convention plugin

**URL:** <https://discuss.gradle.org/t/reference-project-directory-from-kotlin-convention-plugin/48631>\
**Category:** Help/Discuss\
**Created:** [June 6, 2024, 7:26am UTC](https://discuss.gradle.org/t/reference-project-directory-from-kotlin-convention-plugin/48631 "2024-06-06T07:26:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonreye-4tel](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@simonreye-4tel](https://discuss.gradle.org/u/simonreye-4tel)\
**Post date:** [June 6, 2024, 7:26am UTC](https://discuss.gradle.org/t/reference-project-directory-from-kotlin-convention-plugin/48631/1 "2024-06-06T07:26:25Z")

</div>

I’ve created some convention plugins to share with others in my team according to this guide [Sharing build logic in a multi-repo setup Sample](https://docs.gradle.org/current/samples/sample_publishing_convention_plugins.html).

I want to reference the project directory of the project that is using my convention plugin from within the plugin itself. However when I use something like project.layout.buildDirectory it is referencing the build directory for the plugin and not the project using the plugin.

EDIT:

I am using the conventions from the plugin in /buildSrc conventions within a project. I just testing using the conventions from the plugin directly in a subproject gradle build file and it compiled just fine. Is using a convention from a plugin within a /buildSrc convention simply not the correct way to use conventions. I did it this way because there are some commonalities between our various projects but also some differences. Should I move all the conventions, even the more project specific ones, into the plugin.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [June 6, 2024, 9:52am UTC](https://discuss.gradle.org/t/reference-project-directory-from-kotlin-convention-plugin/48631/2 "2024-06-06T09:52:21Z")

</div>

Can you show an [MCVE](https://stackoverflow.com/help/mcve)?  
From what you said, it should work as you expect.

---

<div class="post-metadata">

**Author:** ![simonreye-4tel](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@simonreye-4tel](https://discuss.gradle.org/u/simonreye-4tel)\
**Post date:** [June 6, 2024, 11:47pm UTC](https://discuss.gradle.org/t/reference-project-directory-from-kotlin-convention-plugin/48631/3 "2024-06-06T23:47:10Z")

</div>

I’ll try to get an MVCE up soon but I’m away for a bit. I’ve given more details in my original question.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [June 7, 2024, 8:33am UTC](https://discuss.gradle.org/t/reference-project-directory-from-kotlin-convention-plugin/48631/4 "2024-06-07T08:33:22Z")

</div>

> Is using a convention from a plugin within a /buildSrc convention simply not the correct way to use conventions.

If I got you right, that is exactly the right way. (besides that I prefer using an included build over `buildSrc` but that should not make a difference here).

> Should I move all the conventions, even the more project specific ones, into the plugin.

You can, but you don’t have to. Should not really be relevant to the issue here.

---

<div class="post-metadata">

**Author:** ![simonreye-4tel](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@simonreye-4tel](https://discuss.gradle.org/u/simonreye-4tel)\
**Post date:** [June 11, 2024, 1:57am UTC](https://discuss.gradle.org/t/reference-project-directory-from-kotlin-convention-plugin/48631/5 "2024-06-11T01:57:00Z")

</div>

Thanks for your help [Björn](https://discuss.gradle.org/u/Vampire). Turns out it was more my unfamiliarity with the Kotlin DSL.
