79572102

Date: 2025-04-13 22:08:55
Score: 0.5
Natty:
Report link

After some research I found several solutions to this problem:

  1. Use gradle plugins like fat-aar, however most of them are currently (07.2024) unsupported or don't give the necessary flexibility
  2. Make each module of the application a part of one big library
  3. Gradle Composite Builds but it was very slow and forced us to have all the source code (of the projects) locally, so we abandoned this option

As a prod solution, option 2 was preferred, because it would allow us to connect individual functions without depending on other unnecessary ones


For this purpose, I wrote a small plugin for publishing in buildSrc

plugins {
    `maven-publish`
}

afterEvaluate {
    publishing {
        publications {
            register<MavenPublication>("release") {
                from(components.findByName("release"))

                groupId = project.hierarchy.concatGroup()
                artifactId = project.name
                version = libs.versions.versionName.get()
            }
        }
        repositories {
            maven("...") {
                credentials {
                    username = getLocalProperty("MAVEN_USERNAME")
                    password = getLocalProperty("MAVEN_PASSWORD")
                }
            }
        }
    }
}

And some utils in buildSrc

val Project.hierarchy get(): List<Project> =
    generateSequence(this, Project::getParent).toList().reversed()

fun List<Project>.concatGroup(): String {
    return dropLast(1).joinToString(".") { it.name }
}

Thus, we get the name of the dependencies in the repository the same as the name of the modules tree of your project

And don't forget to connect your maven repository to the gradle project

Then you can connect this plugin to the modules you want to put into the repository (or another plugin as in my case)

plugins {
    id("com.android.library")
    kotlin("android")
    /* ... */
    id("publishing-plugin")
}

After that, you can call the publishAndroidReleasePublicationToMavenRepository or publishReleasePublicationToMavenRepository task, depending on the configuration of your project (KMP or Android).

After that, all modules to which the plugin has been applied will be uploaded to the specified maven repository.


The client can then download any module as a dependency, and that in turn will download all other modules required for correct work

your-app-feature = { group = "YourProject.features.feature", name = "feature", version.ref = "your-proj-version" }

Advantages:

Minuses:


upd:

After a year from the previously found solution.

I Found an article on a Russian resource on this topic using a more modern version of the fat-aar solution - Grease

It may be worth considering switching to such a solution

Reasons:
  • Blacklisted phrase (1): this plugin
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: qveex