smac89
smac89

Reputation: 43068

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

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.

Upvotes: 0

Views: 539

Answers (1)

Strelok
Strelok

Reputation: 51431

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")
}

Upvotes: 2

Related Questions