Custom plugin in a multi java project setup

plugins

(Gadi Eichhorn) #1

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.


(Staffan Forsell) #2

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.


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


(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 -> https://github.com/gadieichhorn/gradle-java-multimodule

Thanks in advance.
Gadi.


(Staffan Forsell) #6

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


(Gadi Eichhorn) #7

thanks @staffanf, can you submit a pull request?

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

Thanks.


(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 = 'another.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:

buildSrc/build.gradle

dependencies {
    runtime subprojects
}

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


(Gadi Eichhorn) #10

awesome! thanks @jjustinic


(Gadi Eichhorn) #11

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