Gradle Composite Build,无法解决传递依赖项 [英] Gradle Composite Build, transitive dependency is not resolved

查看:123
本文介绍了Gradle Composite Build,无法解决传递依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,很抱歉,我不得不用伪代码展示这个问题,因为原始库代码是封闭源代码,并且整个构建过程更加复杂.

First off, I'm sorry I have to showcase the problem in pseudocode, because the original library code is closed source and the overall build process is a little more complicated.

问题如下:

我们有一个项目A,它使用一个内部库B.该库使用几个开源库,我们现在将它们分别称为C和D.

We have a project A, which uses an inhouse library B. This Library uses several opensource libraries, we call them C and D for now.

出于调试目的,我想创建项目A的 gradle复合版本,其中包括使用 includeBuild 的库B.

For debugging purposes I want to create a gradle composite build of project A, which includes library B using, includeBuild.

项目A:settings.gradle

Project A: settings.gradle

rootProject.name = 'A'

includeBuild '../B'

项目A在其build.gradle中包含库B:

And Project A includes Library B in its build.gradle:

repositories {
    mavenCentral()
}

dependencies {
       compile group: 'bgroup', name: 'b', version: '1.0' 
}

库B具有C和D作为依赖项.D有一个自己的存储库,C在MavenCentral上.

Library B has C and D as dependencies. D has a own repository, C is on MavenCentral.

库B build.gradle:

Library B build.gradle:

repositories {

  maven {
    url "http://D-Repository/maven"
  }

  mavenCentral()
}

dependencies {
       compile group: 'dgroup', name: 'd', version: '1.0'
       compile group: 'cgroup', name: 'c', version: '1.6'
}

我可以毫无问题地使用库B的build.gradle文件对其进行编译.但是,当我尝试编译Project A的复合版本时,它会说:

I can compile Library B using its build.gradle file without a problem. But when I try to compile the composite build of Project A, it says it:

找不到dgroup:d:1.0

Could not find dgroup:d:1.0

我确实解析库C,但不解析D .我必须将D的存储库添加到Project A的build.gradle文件中,以使其正常工作.

I does resolve library C, but not D. I have to add the repository of D to the build.gradle file of Project A to make it work.

项目A包括D build.gradle的存储库:

Project A including repository of D build.gradle:

repositories {
     maven {
       url "http://D-Repository/maven"
     }

     mavenCentral()
 }

 dependencies {
       compile group: 'bgroup', name: 'b', version: '1.0' 
 }

因此,即使A不直接将其用作依赖项,我也必须添加D的存储库.

So I have to add the repository of D, even though A does not use it as a dependency directly.

  • 这是预期的行为吗?
  • 我缺少一些配置吗?

如果我只是从我们自己的存储库(没有复合构建)中获取库B,则不必将D的存储库添加到项目A.但是,这样一来,我在处理项目A时就无法调试B.

If I just get library B from our own repository (no composite build), I dont have to add the repository of D to project A. But this way I cannot debug B while working on project A.

推荐答案

如注释中所示,您发布的B是一个胖JAR,其中包含依赖项类.如果您使用复合构建,则按正常方式使用可传递依赖项解析.使用胖JAR作为依赖关系是非常糟糕的做法.

As found out in the comments, your published B is a fat JAR that contains the dependency classes. If you use the composite build, the normal transitive dependency resolution is used how it is meant. Using fat JARs as dependencies is very bad practice.

如果您现在依靠胖JAR的复合版本替换,您将具有适当的依赖项声明,但是A找不到D,因为在它知道的任何存储库中都找不到D.您要么必须用包含的构建中的胖JAR替换对B的依赖关系,要么切换为使用适当的可传递依赖关系处理方式.这将涉及发布正常的B JAR,但是具有声明其依赖项的正确元数据,并将D特定的存储库添加到A,以便它可以解决传递性依赖项.

If you now depend on the composite build replacement of the fat JAR, you have proper dependency declarations, but A cannot find D, as it is not found in any repositories it knows of. You either have to make the dependency on B be replaced by the fat JAR from the included build, or switch to use proper transitive dependency handling how it is meant. This would involve publishing the normal B JAR, but with correct metadata that declares its dependencies and adding the D-specific repository to A, so that it can resolve the transitive dependency.

这篇关于Gradle Composite Build,无法解决传递依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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