Custom plugin in a multi java project setup

Hi,

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.

Thanks,
Gadi.

Place it in buildSrc, then it will be available to the rest of the build.
https://guides.gradle.org/writing-gradle-plugins/ along with https://docs.gradle.org/4.7/userguide/java_gradle_plugin.html covers the basic of getting started.

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

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?
Thanks

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.

Thanks @staffanf

Here is my example code -> https://github.com/gadieichhorn/gradle-java-multimodule

Thanks in advance.
Gadi.

Here’s a patch for a fixed version:
https://pastebin.com/guTtmEU4

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

thanks @staffanf, can you submit a pull request?

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

Thanks.

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 = 'another.id'
            implementationClass = 'some.other.PluginClass'
        }
    }
}
1 Like

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:

buildSrc/build.gradle

dependencies {
    runtime subprojects
}

https://docs.gradle.org/current/userguide/organizing_build_logic.html#sec:build_sources

1 Like

awesome! thanks @jjustinic

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