简体   繁体   中英

Gradle seems to ignore project dependencies

We have a multi-project build with a intra-project dependencies between the 'included' projects in the settings.gradle. There are a number of interdependencies between the various projects expressed as project dependencies included in the moderately sized list of the project's dependencies.

While this approach works fine in several other multi-project builds, in this particular project, the project dependencies are not being honored, therefore sub projects are being built in the wrong order and the build fails.

So, for starters, how do we diagnose what's going on here in order to determine if it is a bug?

We're running: Gradle (Wrapper) Version: 3.1 Operating System: Windows 8.1 6.3 amd64 JDK: Oracle 1.8.0_65


So - we eventually determined that the problem was this - there was code in a configurations.all block that was setting the useVersion on various dependencies. If one of these dependencies happened to be a project dependency, the project dependency piece is broken.

It's hard to answer without seeing the relevant snippets of build.gradle and also an overview of how the offending projects include one another. Here's a couple of likely candidates

Sometimes the evaluation of one project is dependent upon the evaluation of another, in these cases you can use evaluationDependsOn

project(':projectA') {
    evaluationDependsOn(':projectB')
}
project(':projectB') {
    project(':projectA').tasks.create(...)
}

In cases where there's a circular reference between project dependencies you might be able to break the loop by adding extra configuration(s)

project(':projectA') {
    configurations {
       base
       compile.extendsFrom base
    }
    dependencies {
       base 'aaa:bbb:1.0'
       compile project(path: ':projectB', configuration: 'base')
    }
}
project(':projectB') {
    configurations {
       base
       compile.extendsFrom base
    }
    dependencies {
       base 'ccc:ddd:1.0'
       compile project(path: ':projectA', configuration: 'base')
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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