Gradle:多个Java项目的通用资源依赖项 [英] Gradle: common resource dependency for multiple java projects

查看:433
本文介绍了Gradle:多个Java项目的通用资源依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <$ c 

$ c>项目/
子项目-1
/主要/资源
子项目-2
/主要/资源
数据
/主要/ resources
/ test / resources

正如你所看到的,我有多个子项目所有的java),我怎样才能让他们依赖于一些常见的资源(数据项目,其中不包含代码,但只有资源),以及他们自己单独的资源?

另外最好是intellij-idea能够自动地使用JetGradle来获取这些依赖关系(JetGradle在每个子项目中都能很好地获取默认的gradle java项目依赖关系)。

非常感谢!
解决方案

一个解决方案是将Java插件也应用于数据项目,然后使用常规项目依赖项(例如 depe ndencies {runtime project(:data)} )。但是,这需要一些努力来防止运送测试资源。

另一个解决方案是不要让 data 一个Gradle项目,而是将其资源目录包含在其他两个项目中( sourceSets.main.resources.srcDir../date/main/resources; sourceSets.test.resources.srcDir../ data / test / resources)。

I'm developing a multi-module project with gradle/intellij-idea, and here is the structure of my project home:

project/
  sub-project-1
    /main/resources
  sub-project-2
    /main/resources
  data
    /main/resources
    /test/resources

As you can see I have multiple sub-projects (all java), how can I make them depend on some common resources (the "data" project, which contains no code but only resources), as well as their own separate resources?

Also it's best that the intellij-idea can pick up these dependencies with JetGradle automatically (JetGradle do just fine picking up the default gradle java project dependencies within each sub project).

Thanks a lot!

解决方案

One solution is to apply the Java plugin also to the data project, and then use regular project dependencies (e.g. dependencies { runtime project(":data") }). However, this would require a bit of effort to prevent shipping the test resources.

Another solution is not to make data a Gradle project but literally include its resource directories in the other two projects (sourceSets.main.resources.srcDir "../date/main/resources"; sourceSets.test.resources.srcDir "../data/test/resources").

这篇关于Gradle:多个Java项目的通用资源依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆