Publish parent module including child module

project hierarchy

  • parent-module
    – child-module

Hello,
How to publish parent module including child module.

this is build.gradle.kts file at root

publishing {
    publications {
        create<MavenPublication>("maven") {
            groupId = group.toString()
            artifactId = project.name
            version = version.toString()
            from(components["java"])
        }
    }
}

this setting above only publish parent module
so after research I ended up adding this line
from(subprojects.flatMap { it.components["java"] })
under from(components[“java”])
but It didn’t work.

Thank you…

That’s a bad idea, that would try to publish the subprojects component under the coordinates of the parent.

Have a convention plugin for publishing where you apply the maven-publish plugin and do the configuration common to both projects. Apply that convention plugin to both projects. Do additional settings unique to the individual projects in the individual projects build scripts.

(Do not try to do it with allprojects { ... } or subprojects { ... }, that would be bad practice and not recommended.

1 Like