How to create a sample for my custom plugin

plugins

(Stefan M.) #1

I’ve written a gradle plugin which I want to publish to our artifactory.

Currently my custom plugin residence in the buildSrc/ dir.
My root build.gradle.kts can apply it easily with:

import my.package.CustomExtension 

apply {
    plugin("my.awesome.plugin")
}

configure<CustomExtension> {
 // Configuraiton of my extensions
}

That works.

Now I want to apply the artifactory plugin to my custom plugin.
The only thing I’ve added to my buildSrc/build.gradle is:

plugins {
    kotlin("jvm") version("1.2.10")
    id("java-gradle-plugin")
    id("com.jfrog.artifactory") version "4.6.0" // <- This was newly added
}

artifactory { // <- This was newly added

}

And here is the problem. If I try to build now I got always

Unresolved reference: artifactory

The problem don’t exist if I apply it to my root build.gradle.kts.
So I assume that it is a “issue” with the buildSrc/ dir somehow…

How can I solve that?

But I ask me even more if the buildSrc/ the right directory to build a custom plugin?
If not, how can I provide a “sample” how to use my plugin?
Currently my root build.gradle.kts shows exactly how to use it. And I can easily “test” it (just by running my custom task).
But if I put it into a different dir (and apply it as a module) like plugin/ my root build.gradle.kts can’t resolve it anymore.
I’ve tried it here also with a buildscript-setup. Without success :confused:

So basically I’ve two questions:

  1. Is the buildSrc/ the correct dir for developing custom plugins?
  2. How can I create a “sample” (or consumer) of the plugin while developing so I can make sure everything works correctly?

Thanks :slight_smile: :+1: