Skip to content

Minimal example of how to safely share a file produced by a task in one project, with a task in another project.

Notifications You must be signed in to change notification settings

robmoore-i/gradle-share-outputs-between-projects

Repository files navigation

How to share files across Gradle subprojects: A minimal example

Note: There are two branches in this repository: kotlin and groovy.

This is the Gradle project:

.
├── producer
│   └── build.gradle.kts
├── consumer
│   └── build.gradle.kts
└── settings.gradle.kts

Producer

  • Register a single task, which creates a file.
  • Expose ("publish" in the Gradle nomenclature) an artifact containing just that file for sharing across projects in the build.

Consumer

  • Declare a dependency on the producer to consume its exposed ("published") artifact.
  • Register a task which uses ("resolves") that configuration's contained file.

Simple sharing

In simple artifact sharing, we don't add any attributes to our exported configuration in the publisher.

This means that when we want to declare a dependency on this artifact from another project, we need to name the exported configuration directly. This is easy enough to do, but using artifact matching is better because it enables you to tightly couple the references to the same published configuration.

In this repository's code example, simple sharing is demonstrated by the "sharedConfiguration" configuration.

Artifact matching

In artifact-matched sharing, we add attributes to our exported configuration so that consuming projects can automatically select the intended configuration, without having to name it. Using artifact matching enables us to make use of common code (for example, in a plugin) in order to provide a shared, coupled reference to the same artifact, we can use artifact matching.

In this repository's code example, artifact-matched sharing is demonstrated by the "anotherSharedConfiguration" configuration.

About

Minimal example of how to safely share a file produced by a task in one project, with a task in another project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published