为什么Gradle不在编译/运行时类路径中包含传递依赖项? [英] Why doesn't Gradle include transitive dependencies in compile / runtime classpath?

查看:122
本文介绍了为什么Gradle不在编译/运行时类路径中包含传递依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Gradle的工作原理,我不明白它如何解决项目的传递依赖项。

I'm learning how Gradle works, and I can't understand how it resolves a project transitive dependencies.

目前,我有两个项目:

For now, I have two projects :


  • projectA:对外部库有几个依赖项

  • projectB:仅对一个库具有依赖项projectA

无论我如何尝试,在构建projectB时,gradle都不会在projectB的项目中包含任何projectA依赖项(X和Y)编译或运行时类路径。我只能通过将projectA的依赖项包含在projectB的构建脚本中来使其正常工作,我认为这没有任何意义。这些依赖项应自动附加到projectB。我很确定我遗漏了一些东西,但是我不知道是什么。

No matter how I try, when I build projectB, gradle doesn't include any projectA dependencies (X and Y) in projectB's compile or runtime classpath. I've only managed to make it work by including projectA's dependencies in projectB's build script, which, in my opinion does not make any sense. These dependencies should be automatically attached to projectB. I'm pretty sure I'm missing something but I can't figure out what.

我已经读过有关 lib依赖项的信息,但它似乎仅适用于像此处所述的本地项目,而不是外部依赖项

I've read about "lib dependencies", but it seems to apply only to local projects like described here, not on external dependencies.

这是我在根项目(包含projectA和projectB的根项目)中使用的build.gradle:

Here is the build.gradle I use in the root project (the one that contains both projectA and projectB) :

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.3'
    }
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'idea'

    group = 'com.company'

    repositories {
        mavenCentral()
        add(new org.apache.ivy.plugins.resolver.SshResolver()) {
            name = 'customRepo'
            addIvyPattern "ssh://.../repository/[organization]/[module]/[revision]/[module].xml"
            addArtifactPattern "ssh://.../[organization]/[module]/[revision]/[module](-[classifier]).[ext]"
        }
    }

    sourceSets {
        main {
            java {
                srcDir 'src/'
            }
        }
    }

    idea.module { downloadSources = true }

    // task that create sources jar
    task sourceJar(type: Jar) {
        from sourceSets.main.java
        classifier 'sources'
    }

    // Publishing configuration
    uploadArchives {
        repositories {
            add project.repositories.customRepo
        }
    }

    artifacts {
        archives(sourceJar) {
            name "$name-sources"
            type 'source'
            builtBy sourceJar
        }
    }
}

这一个缺点仅cerns projectA:

This one concerns projectA only :

version = '1.0'
dependencies {
    compile 'com.company:X:1.0'
    compile 'com.company:B:1.0'
}

这是projectB所使用的:

And this is the one used by projectB :

version = '1.0'
dependencies {
    compile ('com.company:projectA:1.0') {
        transitive = true
    }
}

在此先感谢您的帮助,请为我的英语不好而道歉。

Thank you in advance for any help, and please, apologize me for my bad English.

推荐答案

最后,问题并非出自脚本。我刚刚清除了gradle的缓存和每个项目的build文件夹,以使其正常工作。

Finally, the problem didn't come from the scripts. I've just cleared gradle's cache, and each project's build folder, to make this work.

这篇关于为什么Gradle不在编译/运行时类路径中包含传递依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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