Custom plugin in a multi java project setup


(Gadi Eichhorn) #1


Using Gradle 4.7.

I have some build code that can benefit from being a plugin. I created a plugin project and try to use it with the other subprojects.

Can anyone share an example project were this setup works?
Seemed that all old examples don’t work.


(Staffan Forsell) #2

Place it in buildSrc, then it will be available to the rest of the build. along with covers the basic of getting started.

In the you can find samples/multiProjectBuildSrc which has a simple working example too.

(Gadi Eichhorn) #3

thanks @staffanf

I cannot make this to work:
When I apply the plugin it tell me it is not found.
'plugin with id xxx not found

I tried with full name or just plugin name.
I have a properties file with the plugin class

  1. my plugin is java (not groovey)
  2. my projects organised in multi level nested folder structure

any java plugin example?

(Staffan Forsell) #4

Create a minimal viable example of what does not work and post it here or on github.
Then we can help you get it started.

(Gadi Eichhorn) #5

Thanks @staffanf

Here is my example code ->

Thanks in advance.

(Staffan Forsell) #6

Here’s a patch for a fixed version:

The main problem was that I don’t think you can have subprojects in buildSrc

(Gadi Eichhorn) #7

thanks @staffanf, can you submit a pull request?

Can you seperate plugins with different properties files in the same buildSrc directory?


(Staffan Forsell) #8

Yes, just use more blocks in the dsl like:

 gradlePlugin {
    plugins {
        integrationPlugin {
            id = 'com.rds.example.gradle.integration-plugin'
            implementationClass = 'com.rds.example.gradle.IntegrationPlugin'
        pluginB {
            id = ''
            implementationClass = 'some.other.PluginClass'

(James Justinic) #9

There’s also nothing wrong with buildSrc being a multi-project build. However, the root project must have a runtime dependency on the subprojects you want to include (see Organizing Build Logic - Build Sources).

There’s no problem including all subprojects in one go, if that’s what you want:


dependencies {
    runtime subprojects

(Gadi Eichhorn) #10

awesome! thanks @jjustinic

(Gadi Eichhorn) #11

thanks @staffanf, cool, this is what I thought.