简体   繁体   English

Gradle Buildship项目依赖周期误报

[英]Gradle Buildship project dependency cycle false positive

So I've got a multi-project gradle build consisting of: 所以我有一个多项目gradle构建,包括:

myapp
myapp2
shared
testLib

Where myapp and myapp2 have compile dependencies on shared . myappmyapp2shared上具有编译依赖项。

The testLib project also has a compile project dependency on shared . testLib项目还对shared拥有一个编译项目依赖项。 It exists to define some unit test helper code which uses shared classes. 它的存在是为了定义一些使用shared类的单元测试助手代码。 These classes live in its main sourceSet, as the purpose of this project is to build library containing test helper classes. 这些类位于其main SourceSet中,因为此项目的目的是构建包含测试帮助程序类的库。

Now the shared project has unit tests. 现在, shared项目具有单元测试。 These tests utilize the helper code in testLib . 这些测试利用testLib的帮助程序代码。 Thus shared has a testCompile project dependency on testLib . 因此, sharedtestLib具有testCompile项目依赖性。

Gradle has no problem with this. Gradle对此没有任何问题。 It understands to first build shared , then build testLib , then run the unit tests in shared just fine. 它理解先构建shared ,然后构建testLib ,然后在shared运行单元测试就可以了。 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}." 在导入构建后,它将其标记为项目依赖周期:“在项目'shared'的构建路径中检测到一个周期。该周期包含项目{shared,testLib}。” and a similar message for the testLib project. 以及针对testLib项目的类似消息。

So why not just roll testLib into the test sourceSet of shared , you might ask? 那么,为什么不将testLib滚动到shared的测试sourceSet中呢? Well, the thing is, some of that unit test helper code is also used by the unit tests in myapp and myapp2 . 嗯,事实是, myappmyapp2的单元测试也使用了某些单元测试帮助程序代码。 Both of these projects have compile project dependencies on shared and testCompile project dependencies on testLib . 这两个项目都具有对shared编译项目依赖性以及对testLib testCompile项目依赖性。

Is there any way to get Buildship to understand that this is not really a project dependency cycle? 有什么方法可以让Buildship了解这实际上不是项目依赖周期吗?

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' } 我已经在这里尝试了部分解决方案: https ://softnoise.wordpress.com/2014/09/07/gradle-sub-project-test-dependencies-in-multi-project-builds/将我的testLib构建更改为此(将测试帮助程序类从main移回test sourceSet后:插件{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: 并通过以下方式更改我的shared项目以引用新的testLib-test.jar

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. gradle再次没有问题并且构建良好,但是在Eclipse中删除并重新导入项目后,Buildship返回与以前相同的周期警告。

Is Buildship just currently unable to handle this kind of situation? Buildship目前是否无法处理这种情况?

I guess this is happening because, eclipse has only a single classpath for the whole project (for both main and test). 我想这是因为eclipse对于整个项目(对于main和test而言)只有一个classpath So where as gradle compile and testCompile as two different configurations - when importing into eclipse you will find issues. 因此,gradle compiletestCompile是两种不同的配置-导入eclipse时,您会发现问题。

You need to get rid of one of the dependencies. 您需要摆脱依赖关系之一。 May be you can create a separate project for tests from testLib. 也许您可以从testLib创建一个单独的测试项目。

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

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