22979

Adding a global resource folder to gradle build to be made available for subprojects

Question:

I have a gradle project which consists of a number of subprojects. I want to add a resource folder which is in the same folder as the subprojects to be on the classpath of all the projects when they run.

The folder structure kinda looks like:

root |__subproject1 |__subproject2 |__subproject3 |__global_resources

I've tried doing something like in the root build.gradle:

allprojects { processResources { from("$rootProject/global_resources/") } }

Or this:

subprojects { dependencies { runtime fileTree(dir: "$rootProject/resources", includes: '*.txt') } }

But running any of the subprojects gives an error that the resource it needs is not available.

How do I go about doing this?

Not sure if it's useful, but this is a scala project. I'm not accustomed to writing gradle tasks, so please don't answer with "make a gradle task to do that". I'm sure it's probably that simple, but I don't have any examples to go with.

Answer1:

I think the easiest and most re-usability friendly way would be to do place all your "global" resources in "global_resources/src/main/resources", add build.gradle to your global_resources folder:

root |__..projects.. |__global_resources |____src |______main |_________resources |___________ ...your resource files... |____build.gradle

build.gradle

apply plugin: "java" name="global_resources"

And then include this project in your other projects:

dependencies { compile project(":global_resources") }

Recommend

  • Android Importing Facebook SDK
  • Flutter google_sign_in error : Unable to merge dex
  • error during vaadin widgetset compilation
  • Crashlytics - Unable to get crash reports when the app crashes while not connected to android studio
  • how to add a library to the dependencies gradle of LIBGDX project
  • uploading a file to Google Drive?
  • failed to instantiate one or more class in android studio
  • update google services from 9.0.0 to 10.0.1 Android studio 2.2
  • Upgraded to Android Studio 3.0: Unable to resolve dependency for ':app@debug/compileClasspath&#
  • react-native-video [android] undefined is not an object (evaluating NativeModuels.UIManager.RCTVideo
  • Convert adjacency matrix to a csv file
  • Android gradle : Error No resource found that matches the given name: attr when refer to an android
  • How to add a filter to Active Admin dashboard?
  • object play not found in scala application
  • Is it possible to “shrink” a PdfPtable?
  • Base Internationalization and “Could not find a storyboard named […]”
  • How to extract a number from a string [duplicate]
  • Rails AREL .where statement
  • How to resolve docker host names (/etc/hosts) in containers
  • Using SWIG with a build system [closed]
  • Installing libCurl - ruby 1.9.3 .. rails 3.2.12 .. Windows
  • What does Main.1 output file do in XCode?
  • Creating a setup.exe in InstallShield in Visual Studio
  • Backward compatibility of Python 3.5 for external modules
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Add reference to ASP.NET 5 Class Library from Framework 4.5 Class Library Project
  • python mysqldb delete row
  • Django Haystack Rebuild Index
  • Does Apportable support to build library binary (.a/.so)?
  • How to retrieve information from antrun back to maven?
  • using System.Speech.Synthesis with Windows10 universal app (XAML-C#)
  • Function calls are not supported. Consider replacing the function or lambda with a reference to an e
  • Android Studio 1.3 RC3. Google Play services out of date. Requires 7571000 but found 6774470
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • Unable to install Git-core+svn by MacPorts
  • VSO Build — Response status code does not indicate success: 404 (Not Found)
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • Convert array of 8 bytes to signed long in C++
  • -fvisibility=hidden not passed by compiler for Debug builds
  • Net Present Value in Excel for Grouped Recurring CF