如何创建其他项目使用的通用Gradle项目 [英] How to create common gradle project used by other projects
问题描述
我有一个gradle项目,该项目包含3个部分:客户端,通用和服务. 在客户端项目和服务项目中都有一些类,因此我想创建一个通用模块并从中构建一个jar,然后将其作为库导入其他两个项目中.我将共享类放在通用模块中,我没有创建主类,因为我想设计为仅提供其他类,所以它看起来像这样:
I have a gradle project that consist of 3 parts: client, common and service. There are some classes that are used both in client project and service project, therefore I wanted to create a common module and build a jar from it and then import it in other two projects as a library. I put shared classes in common module, I didnt create the main class because I want to project to only provide other classes, so it looks like this:
然后我尝试将其作为库导入其他项目并进行构建,但是当我尝试使用gradle进行构建时,会引发来自公共模块的有关类的一堆错误:
Then I tried to import it in other project as a library and build them, but when I try to build it with gradle it throws a bunch of errors about the classes from common module:
我在网上找不到任何有关如何使用gradle制作通用模块的教程.任何帮助将不胜感激!
I couldnt find any tutorials online how to make a common module with gradle. Any help would be appreciated!
推荐答案
假定所有三个模块都是同一多模块构建的一部分,然后在client\build.gradle
和service\build.gradle
中添加:
Assuming all three modules are part of the same multi-module build then in client\build.gradle
and service\build.gradle
you add:
dependencies {
implementation project(':common')
}
project(:module)
语法在项目依赖文档中进行了描述.
但是,如果common
,client
和service
是单独的项目并且不共享相同的根build.gradle
,则必须将common
模块发布到共享存储库中,并像任何常规依赖项一样使用它.使用Maven本地存储库最简单.
However if common
, client
and service
are separate projects and don't share the same root build.gradle
you have to publish the common
module into a shared repository and use it like any regular dependency. Easiest to do with Maven Local repository.
这篇关于如何创建其他项目使用的通用Gradle项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!