Reference project directory from Kotlin convention plugin

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.

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.

Can you show an MCVE?
From what you said, it should work as you expect.

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.

1 Like

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.

Thanks for your help Björn. Turns out it was more my unfamiliarity with the Kotlin DSL.

1 Like