将一个项目的构建作为其他资源包含在gradle中

时间:2018-08-29 07:36:51

标签: java gradle

在gradle(4.10)中,我希望同一个项目(作为资源)使用由一个项目编译的资源(css / js)。

项目结构:

site (compiles all children into java jar)
|--server (java server files)
|--client (precompiled js/sass -> compiled production resources)
|--... (more)

现在,我希望server能够(在开发环境中运行时)访问client产生的文件。

结构:

site
|--src/main/resources (more resources, licenses, etc.)
|--build
|  |--lib
|     |--site.jar (production runnable jar including all files from server, client and possible other sub-projects.)
|
|--server
|  |--build
|  |  |--lib
|  |     |--server.jar (runnable jar packaged with everything, including client's resources)
|  |--src/main/java (java server files)
|  |--src/main/resources (server resource files like configs etc.)
|
|--client
   |--src
   |  |--js
   |  |--sass
   |  |--...
   |--build
      |--dist (compiled js and css from sass)
      |--lib
         |--client.jar (not runnable, contains compiled files from dist and can/will be included in server.jar)

基本上,在开发中运行server时,它应该可以访问client的{​​{1}}(将其作为资源进行处理),以便服务器可以将编译后的css / js作为静态内容提供,并且当编译为build/dist时,这些资源应以库server.jar的形式包括在内。注意client.jar是可运行的。 server.jar是带有附加注入模块的服务器包装(不是此问题的主题)。

到目前为止,我已经完成了客​​户端和服务器的编译工作(它们生成.jars,但是site.jar不包括server.jar,也看不到客户端正在开发中)。

整个问题旨在建立上述服务器与客户端之间的连接。

编辑1:

client.jar

这非常好(没有复制和文件重复),但是引入了一些耦合。它还只能解决整个问题的一部分-资源存在于dev中并编译为sourceSets { main { java { srcDirs = ['src/main/java'] } resources { srcDirs = ['src/main/resources', project(':client').buildDir.absolutePath + '/dist'] } } } ,但这并不是真正的“良好”依赖关系。我想学习如何建立对server.jar的依赖。

0 个答案:

没有答案