简体   繁体   English

如何停止在Gradle中被另一个项目替换的项目依赖关系?

[英]How to stop a project dependency being replaced by another project in Gradle?

I have a multi-project setup and I am defining a project as a dependency in the build.gradle file. 我有一个多项目安装程序,我正在将一个项目定义为build.gradle文件中的依赖项。 But that project is being replaced by another project in the same hierarchy. 但是该项目将被相同层次结构中的另一个项目替换。 How do I stop this from happening? 如何阻止这种情况的发生?

Consider the project structure as: 考虑项目结构为:

A/B/C1/D/src
A/B/C2/D/src

In the build.gradle file inside C1/D, I have defined the project C2/D as a dependency. 在C1 / D内的build.gradle文件中,我已将项目C2 / D定义为依赖项。 But then on calling the build task, the dependency C2/D gets replaced by C1/D which is resulting in the following error: 但是随后在调用构建任务时,依赖关系C2 / D被C1 / D替换,这导致以下错误:

Circular dependency between the following tasks:
:B:C1:D:compileJava
\--- :B:C1:D:compileJava (*)

The build runs fine if I call :C1:build but on calling the build task the error appears. 如果我调用:C1:build则构建运行良好,但是在调用构建任务时会出现错误。

On running the :B:C1:D:dependencies I can see the following: 在运行:B:C1:D:dependencies我可以看到以下内容:

+--- project :B:C2:D -> project :B:C1:D (*)

How can I stop this from happening? 我该如何阻止这种情况的发生?

Since the signatures (class names with packages) are the same, gradle takes code from the same project in build task. 由于签名(带有包的类名)是相同的,因此gradle在构建任务中从同一项目中获取代码。 I would suggest using different names for the code in both projects (for example impl infix). 我建议在两个项目中为代码使用不同的名称(例如impl infix)。

Otherwise you need to have a lot of resources (time and willingness) and use separate classloaders for the resources explicitly. 否则,您需要拥有大量资源(时间和意愿),并为资源明确使用单独的类加载器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM