Skip to content

Suggestion to make a shadowed jar the default output of a project #1893

@bric3

Description

@bric3

Describe your use-case which is not covered by existing documentation.

In a multi-project, a project foo — that is consumed by other projects — needs to shadow one or more its packages. And there's no need for the "regular" non shadowed "output".

One can write in a consuming project :

dependencies {
  implementation(project(path = ":foo", configuration = "shadow"))
}

However, this is not ideal as it allows to mistakenly declare implementation(project(":foo")) thus providing unshadowed packages / dependencies.

I suggest documenting the following example to address this usage.

As a reminder in Gradle, on a java library, folk are used to api, implementation, runtimeOnly (and compileOnly configurations). These configurations are where dependencies are declared (they are declarable). But when consuming a project like project(":foo"), Gradle looks for consumable configurations, and there are apiElements (for compilation) and runtimeElements (for runtime) for java library project.

So I suggest to document the tuning of these consumable configurations, to only have one declaration of the project without thinking about exposed configurations.

Consuming projects :

dependencies {
  implementation(project(":foo"))
}
configurations {
  named("apiElements") {
    outgoing.artifacts.clear()
    outgoing.artifact(tasks.shadowJar))
    exclude(group = "org.eclipse.jetty")
  }
  named("runtimeElements") {
    outgoing.artifacts.clear()
    outgoing.artifact(tasks.shadowJar)
    exclude(group = "org.eclipse.jetty")
  }
}

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

https://gradleup.com/shadow/multi-project/

Are you interested in contributing to the documentation?

I can do this part of the documentation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions