将外部资源添加到另一个项目的gradle中

将外部资源添加到另一个项目的gradle中

本文介绍了将外部资源添加到另一个项目的gradle中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有资源"库的项目(不是基于Java的).它仅包含多个Java项目使用的文件层次结构

I have a project that has a "resources" library (not java based). It simply contains a hierarchy of files that are used by multiple java projects

library
   files
   binaries
   etc

在我的一个Java项目中,我想将这些文件包含在组装好的jar文件中

In one of my java projects, I want to include these files in the assembled jar file

// current definition of a sample project
project("java_project") {
 // dependencies omitted

 jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }

    manifest {
        attributes("Main-Class": "mymainclass")
    }
  }
}

project("library") {
  // is in settings.gradle
}

如何使用其他项目资源更新jar?我需要在项目外部使用它们,因为相同的资源由多个项目共享.

How would I update the jar with the other project resources? I need them outside of the project because the same resources are shared by multiple projects.

推荐答案

也许有人会有更好的解决方案,但我在jar闭包中添加了以下内容:

Perhaps someone will have a better solution but I added the following to the jar closure:

from { fileTree(dir: "library") }

然后,我可以使用"exclude"和"include"过滤器控制文件:

I then can control the files with the exclude and include filters:

http://www.gradle.org/docs/current/userguide/working_with_files.html

这篇关于将外部资源添加到另一个项目的gradle中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 12:36