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

你说的曾经没有我的故事 提交于 2019-12-12 01:52:21

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/43194562/adding-a-global-resource-folder-to-gradle-build-to-be-made-available-for-subproj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!