简体   繁体   English

IntelliJ从根项目执行gradle测试

[英]IntelliJ execute gradle test from root project

I've a gradle multiproject importend in my IntelliJ, and I want execute some test classes. 我在IntelliJ中有一个gradle多项目importend,我想执行一些测试类。

The structure is like: 结构如下:

root
|-module-a
|-module-b

module-a depends on module-b , so in the build.gradle module-a取决于module-b ,因此在build.gradle中

dependencies {
    compile project('module-b');
}

When I use gradle from the shell everything it's ok, I have to go in the root project dir and write: 当我从外壳上使用gradle时,一切正常,我必须进入项目目录并编写:

./gradlew :module-a:test

And everything it's been tested. 一切都经过测试。

When I click " Run 'Tests' in 'module-a' " from IntelliJ I have this error: 当我从IntelliJ中单击“ 在'module-a'中运行'测试' ”时,出现此错误:

A problem occurred evaluating root project 'module-a'.
> Project with path ':module-b' could not be found in root project ':module-a'.

So it seems, that IntelliJ is executing the gradle command from module-a and not from the root (this should be the correct behavior from what gradle wants). 如此看来,IntelliJ是从模块 -a而不是从根目录执行gradle命令(这应该是gradle想要的正确行为)。

How can execute this test inside IntelliJ? 如何在IntelliJ中执行此测试? What I have to configure? 我必须配置什么?

For a multi-project structure that looks like this 对于如下所示的多项目结构

root
|-module-a
|-module-b

There is only one settings.gradle in the root folder, with the content: 根文件夹中只有一个settings.gradle ,其内容为:

include 'module-a', 'module-b'

The subproject folders do not contain a settings.gradle file. 子项目文件夹不包含settings.gradle文件。 Then you refer to sibling projects as: 然后,您将同级项目称为:

project(':module-b')

so your dependency would be declared as: 因此您的依赖项将声明为:

dependencies {
  compile project(':module-b');
}

Please see here for more information about multi-project structure. 参阅此处以获取有关多项目结构的更多信息。

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

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