You can open this sample in an IDE that supports Gradle.

This sample shows how convention plugins can be shared and applied to both the production code and the build logic code in buildSrc.

Let’s use the following project structure:

KotlinGroovy
Project structure
├── application
   ├── src
      └── main
   └── build.gradle
├── build-conventions
   ├── src
      ...
   ├── build.gradle
   └── settings.gradle
├── buildSrc
   ├── src
      ...
   └── build.gradle
├── list
   ├── src
      ...
   └── build.gradle
├── utilities
   ├── src
      ...
   └── build.gradle
└── settings.gradle

The build is configured as follows:

KotlinGroovy
settings.gradle
rootProject.name = 'sample'
includeBuild 'build-conventions'
include 'application', 'utilities', 'list'

The shared convention plugin myproject.java-conventions is implemented in an included build called build-conventions. The build is then included in the root project’s settings file as seen in the above snippet. For more details about included builds, see Composing Builds chapter.

The myproject.java-conventions plugin is then applied to the buildSrc build:

KotlinGroovy
buildSrc/build.gradle
plugins {
    id 'myproject.java-conventions'
    id 'groovy-gradle-plugin'
}

It is also applied in the subprojects of the root project:

KotlinGroovy
application/build.gradle
plugins {
    id 'myproject.java-conventions'
    // myproject.greeting is implemented in the buildSrc project that has myproject.java-conventions applied as well
    id 'myproject.greeting'
    id 'application'
}
utilities/build.gradle
plugins {
    id 'myproject.java-conventions'
    id 'java-library'
}
list/build.gradle
plugins {
    id 'myproject.java-conventions'
    id 'java-library'
}

For more details on authoring custom Gradle plugins, consult the user manual.