vanniktech/gradle-maven-publish-plugin

How to publish multi-module project as a single artifact

daniel-rusu opened this issue · 2 comments

I'm creating a multi-module Kotlin project and would like to publish it as a single artifact. Ideally, I would like to apply the plugin at the root level and add some configuration to specify which modules to aggregate into the artifact.

I read all the documentation and searched Google but couldn't find any examples of how to use this plugin to combine all the modules into a single artifact when publishing.

Is this possible or is there another way to accomplish this?

Thanks in advance

Have you tried:

  1. Configure the root module to depend on all the submodules
  2. Apply the shadow plugin in the root module
  3. Configure the publish plugin for the root module

This should create an uber jar that contains all of your subprojects.

Thanks for the suggestion. Taking a step back, I realized that the motivation behind my question was that I wanted users to be able to use my library with a single dependency so I ended up publishing a BOM instead as that seems like the cleanest approach.

This ends up publishing all the modules as separate artifacts along with a BOM artifact that references those artifacts at that release version. This allows users to depend on just the BOM artifact to pull everything and also has the flexibility of allowing users to skip the BOM and depend on only some of the modules if they don't want everything.

In case anyone is searching for this in the future, I accomplished this by creating another module named bom which depends on all the other modules that I want to publish and applied the java-platform plugin in order to generate a maven BOM.

The gradle.properties for the bom module looks like this:

POM_ARTIFACT_ID=bom
POM_NAME=Bill of Materials
POM_DESCRIPTION=The bill of materials allows users to have a single dependency that includes all the modules of this library.

The rest of the properties for publishing are defined at the root level to avoid duplicating them for each module.

The build.gradle.kts for the bom module looks something like this:

plugins {
  id("java-platform")
  id("com.vanniktech.maven.publish") version "0.28.0"
}

javaPlatform {
    allowDependencies()
}

repositories {
    mavenCentral()
}

dependencies {
    constraints {
        // All the modules that you want the BOM to reference
        api(project(":module-one"))
        api(project(":module-two"))
       // etc.
    }
}