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

Overview

How to share files across Gradle subprojects: A minimal example

This is the Gradle project:

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

### producer/build.gradle.kts ###

# - Register a single task, which creates a file.
# - Publish an artifact which contains just that file.

val outputFile = project.layout.buildDirectory.dir("some-subdir").map { it.file("shared-file.txt") }
val makeFile = tasks.register("makeFile") {
    outputs.file(outputFile)
    doFirst {
        outputFile.get().asFile
            .writeText("This file is shared across Gradle subprojects.")
    }
}

val sharedConfiguration: Configuration by configurations.creating {
    isCanBeConsumed = true
    isCanBeResolved = false
}

artifacts {
    add(sharedConfiguration.name, makeFile.map { it.outputs.files.singleFile })
}

### consumer/build.gradle.kts ###

# - Declare a dependency on the producer to consume its published configuration.
# - Register a single task, which resolves that configuration and uses the file. Explicitly depend on the execution of the producing task.

val sharedConfiguration: Configuration by configurations.creating {
    isCanBeConsumed = false
    isCanBeResolved = true
}

dependencies {
    add(sharedConfiguration.name, project(mapOf("path" to ":producer", "configuration" to "sharedConfiguration")))
}

tasks.register("showFile") {
    dependsOn(":producer:makeFile")
    doFirst {
        logger.lifecycle(sharedConfiguration.singleFile.absolutePath)
    }
}
You might also like...
An example that demonstrates how to integrate a learning app with the EIDU platform

EIDU Sample Learning App This app is an example of how to create a learning app that integrates with the EIDU platform. Please consult dev.eidu.com fo

Quality-Tools-for-Android 7.5 0.0 L5 Java This is an Android sample app + tests that will be used to work on various project to increase the quality of the Android platform.
Quality-Tools-for-Android 7.5 0.0 L5 Java This is an Android sample app + tests that will be used to work on various project to increase the quality of the Android platform.

Quality Tools for Android This is an Android sample app + tests that will be used to work on various project to increase the quality of the Android pl

Sample Project for Android Support Library 23.2
Sample Project for Android Support Library 23.2

SnapShot: Contains features Vector Drawable Animated Vector Drawable AppCompat DayNight theme Bottom Sheets Using BottomSheetDialog in day-night mode.

A project which demonstrate how to develop a custom client on android for dribbble.com
A project which demonstrate how to develop a custom client on android for dribbble.com

##What is this? This is a project with custom client app on android for https://dribbble.com, which you can browse the popular icon and animation, lik

This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shadows etc...

Android L preview example Description This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shad

A sample project which can be used as a base in order to develop Media Library applications for Android TV.  Follow the series of blogs starting at http://www.malmstein.com/blog/2014/10/21/building-applications-for-android-tv/ in order to keep up to date with the process
This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shadows etc...

Android L preview example Description This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shad

Eutamin-C Sample Project
Eutamin-C Sample Project

here-is-my-card About Eutamin-C Sample Project This is an android application using Euphony library "here-is-my-card" makes it easy to share business

Playground Android project to test jacoco-report github action

jacoco-android-playground Playground Android project to test jacoco-report github action Running Code Coverage at Module level The app module has mult

Owner
Rob Moore
I like making tools. He/him
Rob Moore
Annotation processor that generates a kotlin wrapper class for a java file, enabling named parameters for kotlin callers.

Annotation processor that generates a kotlin wrapper class for a java file, enabling named parameters for kotlin callers.

Josh Skeen 10 Oct 12, 2022
Demonstration of a StrandHogg attack via the task switcher

StrandHogg attack recents App under attack android:launchMode="singleTask" Attacker app android:launchMode="singleTask" android:taskAffinity="com.exam

Jeroen Mols 2 Oct 25, 2021
Deletes other specs before the compileGroovy gradle task

run-groovy-spec-faster Template ToDo list Create a new IntelliJ Platform Plugin Template project. Get familiar with the template documentation. Verify

null 0 Nov 27, 2021
Learning RxJava for Android by example

Learning RxJava for Android by example This is a repository with real-world useful examples of using RxJava with Android. It usually will be in a cons

Kaushik Gopal 7.6k Dec 30, 2022
Basic example of using ItemTouchHelper to add drag & drop and swipe-to-dismiss to RecyclerView.

Another drag and swipe library? This project is an example of basic drag & drop and swipe-to-dismiss with RecyclerView using ItemTouchHelper. It corre

Paul Burke 2.5k Dec 24, 2022
This is a simple example of Aspect Oriented Programming in Android

Android-AOPExample This is a simple example of Aspect Oriented Programming in Android as part of a blog post I have written. The idea was to measure h

Fernando Cejas 422 Nov 25, 2022
This repo contains example code for O'Reilly's "Programming Android" by Zigured Mednieks, Laird Dornin, Blake Meike and Masumi Nakamura

This repo contains working code for the example in O'Reilly's _Programming Android, 2nd Edition_; Mednieks, Dornin, Meike, Nakamura (http://shop.orei

G. Blake Meike 214 Nov 25, 2022
This repo contains example code for O'Reilly's "Programming Android" by Zigured Mednieks, Laird Dornin, Blake Meike and Masumi Nakamura

This repo contains working code for the example in O'Reilly's _Programming Android, 2nd Edition_; Mednieks, Dornin, Meike, Nakamura (http://shop.orei

G. Blake Meike 165 Nov 11, 2022
Learning RxJava for Android by example

Learning RxJava for Android by example This is a repository with real-world useful examples of using RxJava with Android. It usually will be in a cons

Kaushik Gopal 7.6k Dec 29, 2022
Example app for shortcuts

Android Shortcuts Example app for shortcuts in design library v25 Demo Manifest Add meta-data before </activity> tag in Manifest.xml <meta-data androi

Pamir Cevikogullari 334 Nov 29, 2022