Precompiled script plugins in buildSrc\src\main\kotlin not recognised

I’m trying to write a couple of simple script plugins for a multi-module project I’m creating.

My build.gradle.kts (in the buildSrc directory) has this:

plugins {
    `kotlin-dsl`
    `android-base`
 }

but ‘android-base’ (which is buildSrc\src\main\kotlin\android-base.gradle.kts) is not recognised (unresolved reference).

Can anyone suggest a way to resolve this?

Just to avoid misunderstanding.
You have that snippet in buildSrc/build.gradle.kts?
That is the build script for building your plugin.
So when this build script is evaluated your plugin is not yet built.
So you cannot apply the plugin to that build, that’s a hen-and-egg situation.
But I actually doubt that is really what you intend, because you build Gradle plugins in this build and not some Android code.

H there,

Yes, that snippet is in my buildSrc/build.gradle.kts

I’m trying to replicate the example 9 from here: Developing Custom Gradle Plugins with a custom script that has common settings like compileSDKVersion, etc.

Yeah, but you apply it to the wrong build script.
You should apply it to the build script of your main build, not to your buildSrc build script.

Ah right. I’ll give that a go.

Thanks for the response.

1 Like