简体   繁体   中英

Gradle Buildship project dependency cycle false positive

So I've got a multi-project gradle build consisting of:

myapp
myapp2
shared
testLib

Where myapp and myapp2 have compile dependencies on shared .

The testLib project also has a compile project dependency on shared . It exists to define some unit test helper code which uses shared classes. These classes live in its main sourceSet, as the purpose of this project is to build library containing test helper classes.

Now the shared project has unit tests. These tests utilize the helper code in testLib . Thus shared has a testCompile project dependency on testLib .

Gradle has no problem with this. It understands to first build shared , then build testLib , then run the unit tests in shared just fine. Buildship however, does not. It flags this as project dependency cycles after I import the build: "A cycle was detected in the build path of project 'shared'. The cycle consists of projects {shared, testLib}." and a similar message for the testLib project.

So why not just roll testLib into the test sourceSet of shared , you might ask? Well, the thing is, some of that unit test helper code is also used by the unit tests in myapp and myapp2 . Both of these projects have compile project dependencies on shared and testCompile project dependencies on testLib .

Is there any way to get Buildship to understand that this is not really a project dependency cycle?

EDIT:

I have tried part of the solution here: https://softnoise.wordpress.com/2014/09/07/gradle-sub-project-test-dependencies-in-multi-project-builds/ changing my testLib build to this (after moving the test helper class back into the test sourceSet from main ): plugins { id 'java' }

configurations {
    testOutput
}

dependencies {
  compile project(':shared')
}

task jarTest (type: Jar) {
    from sourceSets.test.output
    classifier = 'test'
}

artifacts {
    testOutput jarTest
}

and changing my shared project to reference the new testLib-test.jar via:

testCompile project(path: ':testLib', configuration: 'testOutput')

Still no luck. Once again gradle has no issues and builds fine, but after deleting and re-importing the project in eclipse, Buildship returns the same cycle warnings as before.

Is Buildship just currently unable to handle this kind of situation?

I guess this is happening because, eclipse has only a single classpath for the whole project (for both main and test). So where as gradle compile and testCompile as two different configurations - when importing into eclipse you will find issues.

You need to get rid of one of the dependencies. May be you can create a separate project for tests from testLib.

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