How to Develop Multiple Repositories (Gradle)
In some cases, it is necessary to make changes to sources in multiple repositories simultaneously. In particular, when
developing new features in Kotlin, it is common to have to expand functionality in the
common-module.
There are two ways to achieve this depending on the frequency and intrusiveness of the changes in the common module.
Using a local package directory.¶
If the changes are purely additive and can be isolated to a new package, a new cards.arda.common.lib or
cards.arda.common sub-package can be created in the local project’s source tree. This package will be temporarily
private to the repository and project that creates it. The intent is that once the additions are stabilized, they can be
moved to the common-module repository and project and published as a new version. At that point, the local project
needs to remove the local package and update its dependencies to use the new version of the common-module package.
Using includeBuild capabilities of Gradle.¶
For changes that affect existing packages in the common-module, or that need to be shared with other projects right
away, development should happen directly in the common-module repository and project. Gradle supports this scenario
through its Composite Builds features. To take
advantage of them:
- Clone the
common-moduleto a directory accessible from the directory of the local project but separate from it.
-
In the local project, if not already done, add the
common-moduleas a dependency.
- For gradle to pickup the local copy
- Use the command-line parameter:
./gradlew --includeBuild=".../path/to/common-module- or create the file
~/.gradle/init.d/common-library.init.gradle.kts:
gradle.settingsEvaluated { val localDependencies = settings.providers.gradleProperty("localDependencies").getOrElse("") if (localDependencies.isBlank()) { println("Build will not include local files. Define 'localDependencies' property to include them.") } else { println("Build will include dependencies from $localDependencies. Undefine 'localDependencies' property to exclude them.") settings.includeBuild(localDependencies) } }
and define thelocalDependenciesproperty in the~/.gradle/gradle.propertiesfile of the local project:
# absolute path to the module, or path relative from the caller localDependencies=.../path/to/common-module
Once testing is done, comment, or remove, thelocalDependenciesproperty from the~/.gradle/gradle.properties
file to avoid including local changes in future builds.
- or create the file
- Have the IDE refresh its Gradle project configuration to pick up the changes.
- Use the command-line parameter:
Once modifications are done, create a PR for the common-module repository and another PR for the local project.
The local project PR should
- declare dependencies to the new
common-moduleversion. -
add an important admonition to the local project PR linking to the
common-modulePR.