Gradle: Selective Dependency Bundling and Documentation in Published Artifacts"

20 views Asked by At

I'm working on a multi-module Gradle project named "layers" with the following structure:

layers/
|- build.gradle.kts
|- settings.gradle.kts
|- buildSrc/
|  - build.gradle.kts
|- layers-sdk/
|  - build.gradle.kts
|- layers-api/
|  - build.gradle.kts
|- libs/
|  - build.gradle.kts

In my settings.gradle.kts, I've included subprojects like this:

include(
    "layers-sdk",
    "layers-api",
    "libs",
)

For generating a fat Jar for my SDK using shadowJar, I've configured it in layers-sdk/build.gradle.kts as follows:

  tasks.shadowJar {
    archiveClassifier.set("")

    configurations = listOf(project.configurations.getByName("runtimeClasspath"))

    minimize()

    manifest {
      attributes(
        "Implementation-Title" to project.name,
        "Implementation-Version" to project.version
      )
    }
    from(tasks.named("javadoc")) { into("docs/javadoc") }
  }

However, my project has other dependencies declared in the dependencies block of layers-sdk/build.gradle.kts:

dependencies {
 // implementation dependencies
 implementation(project(":libs"))

 // api dependencies
 api(libs.caffeine)
 ... 

This configuration is embedding all dependencies into my Jar when publishing using the maven-publish plugin:

  publishing {
    publications {
      create<MavenPublication>("main") {
        project.shadow.component(this)
        version = scmVersion.version
      }
    }
  }

What I aim to achieve is to have shadowJar bundle only the implementation dependencies and leave the API dependencies to be resolved by Maven when importing the SDK into other projects. Additionally, I'm seeking a way to make the documentations available when importing my SDK.

Can someone guide me on how to configure shadowJar to achieve this, and how to include the documentation in the published artifacts?

TL;DR

I'm working on a multi-module Gradle project with several subprojects. I'm using shadowJar to generate a fat Jar for my SDK, but it's bundling all dependencies, including API ones. I want to configure shadowJar to include only implementation dependencies and leave API dependencies for Maven to resolve. Also, I'm looking for guidance on including documentation in the published artifacts.

0

There are 0 answers