I am developing my first gradle plugin. It creates a task. I published to Gradle portal. In my the other project, I apply that plugin to one of module of the project, I can see that task gets created. But when I apply the plugin to my buildSrc’s build.gradle.kts, I could not see the task.
You can, it is just now shown in IntelliJ integration. buildSrc is a bit special and when requesting the tasks for the parent project, Gradle does not deliver the buildSrc tasks to IntelliJ.
If you switch from buildSrc to an included build, it should work like you expect it to.
Is it possible to do it via command line? I tried ./gradlew :buildSrc:sayhi does not work. build.gradle.kts (buildSrc)
I did try included build and can see the created task. But I have to use buildSrc for a particular reason. Sorry belos is a bit off topic but I have to explain.
I defined some classes that I want to access in all build.gradle.kts files including the root project’s build.gradle.kts. But there is a problem accessing those classes in plugins block when using included build. I followed this How to use Composite builds as a replacement of buildSrc in Gradle | by Yury | Bumble Tech | Medium to create an empty plugin and applied to modules so they can access classess in included build. But in plugins block I can’t access those classess. With bulidSrc it works just fine, and I don’t need to create the plugin and apply to all modules.
A snippet of code in root project’s build.gradle.kts:
kotlin("jvm") version "1.7.21"
// from buildSrc's classes, works fine.
// apply plugin from included build, cannot access the class in included build.
And my custom gradle plugin is to scan those files and process.
Well, you found out most facts already, so I have not much to add.
Maybe that the plugin-applying trick might work if you apply the plugin in the settings script as the settings script class loader is parent of the build script class loaders so the classes should be available.
And that you should probably consider to neither use an included build nor buildSrc to define versions or plugins, but use a version catalog instead.