Sharing convention plugins with build logic build Sample
version 8.10
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:
Project structure
├── application
│ ├── src
│ │ └── main
│ └── build.gradle.kts
├── build-conventions
│ ├── src
│ │ ...
│ ├── build.gradle.kts
│ └── settings.gradle.kts
├── buildSrc
│ ├── src
│ │ ...
│ └── build.gradle.kts
├── list
│ ├── src
│ │ ...
│ └── build.gradle.kts
├── utilities
│ ├── src
│ │ ...
│ └── build.gradle.kts
└── settings.gradle.kts
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:
settings.gradle.kts
rootProject.name = "sample"
includeBuild("build-conventions")
include("application", "utilities", "list")
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:
buildSrc/build.gradle.kts
plugins {
id("myproject.java-conventions")
`kotlin-dsl`
}
repositories {
// for kotlin-dsl plugin
gradlePluginPortal()
}
buildSrc/build.gradle
plugins {
id 'myproject.java-conventions'
id 'groovy-gradle-plugin'
}
It is also applied in the subprojects of the root project:
application/build.gradle.kts
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.kts
plugins {
id("myproject.java-conventions")
id("java-library")
}
list/build.gradle.kts
plugins {
id("myproject.java-conventions")
id("java-library")
}
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.