This is an example project to use monodiff with Gradle multi-project build. It is worth mentioning that monodiff itself does not depends on Gradle.
In this example, there are four subprojects:
They have the following dependency:
By using monodiff, only changed apps can be built as follows:
- When the
apps/inventory-appis changed, only theapps/inventory-appwill be built.
- When the
libs/greeteris changed, only theapps/account-appwill be built.
- When the
libs/profileis changed, both theapps/account-appand theapps/inventory-appwill be built.
This dependency is declared in build.gradle.kts of each app.
dependencies {
implementation(project(":libs:greeter"))
implementation(project(":libs:profile"))
// ...
}Aside from this, monodiff.json declares dependency for monodiff.
{
"apps/account-app": {
"deps": ["build.gradle.kts", "settings.gradle.kts", "libs/greeter", "libs/profile"]
},
"apps/inventory-app": {
"deps": ["build.gradle.kts", "settings.gradle.kts", "libs/profile"]
}
}Each key, e.g. apps/account-app, represents a directory to be rebuilt when its dependencies are changed. For example, apps/account-app will be rebuilt when build.gradle.kts, settings.gradle.kts or files under apps/account-app, libs/greeter or libs/profile are changed.
In this monodiff.json, only apps are listed and libs are not listed. This is because what we want to detect here is affected roots of dependency. When the affected app is built, depending libs will be automatically built by the Gradle's dependency management system.
By default, monodiff command outputs affected sub-projects as follows:
$ git diff --name-only origin/master | monodiff
apps/account-app
apps/inventory-app
When you use Gradle multi-project build, there are some useful options. The output of the following command can be used as an argument of gradle command to build only affected sub-projects.
$ git diff --name-only origin/master | monodiff --prefix ":" --separator ":" --suffix :build
:apps:account-app:build
:apps:inventory-app:build