Skip to content

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-module to 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-module as a dependency.

    • in the gradle/libs.versions.toml file:

      arda-common-version = "2.0.0"
      
      arda-common = { module = "cards.arda.common:lib", version.ref = "arda-common-version"}
      
      • in the build.gradle file:
      dependencies {
        implementation(libs.arda.common)
      }
      
  • 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 the localDependencies property in the ~/.gradle/gradle.properties file 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, the localDependencies property from the ~/.gradle/gradle.properties
        file to avoid including local changes in future builds.
    • Have the IDE refresh its Gradle project configuration to pick up the changes.

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-module version.
  • add an important admonition to the local project PR linking to the common-module PR.

    > [!IMPORTANT]
    > This PR depends on the changes in the PR [`common-module` #<pull-request-number>](https://github.com/Arda-cards/common-module/pull/<pull-request-number>) . Please review and merge it first.
    >
    

Comments