2

My settings.gradle file looks like:

include "serverTest", "shared"

And the serverTest build.gradle file looks like:

group = 'gradle'
version = '1.0'
defaultTasks 'build'
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = JavaVersion.VERSION_1_6

dependencies
{
  compile project(':shared')
}

The directory structure is: The top level holds the settings.gradle file and it has folders shared and serverTest in it. Then in the serverTest directory there is the build.gradle file.

When I run gradle at the top level it outputs:

:shared:compileJava UP-TO-DATE
:shared:processResources UP-TO-DATE
:shared:classes UP-TO-DATE
:shared:jar UP-TO-DATE
:serverTest:compileJava UP-TO-DATE
:serverTest:processResources UP-TO-DATE
:serverTest:classes UP-TO-DATE
:serverTest:jar UP-TO-DATE
:serverTest:assemble UP-TO-DATE
:serverTest:compileTestJava
:serverTest:processTestResources UP-TO-DATE
:serverTest:testClasses
:serverTest:test

I don't want it to execute the task :serverTest:test though. I tried changing my defaultTasks to just compileJava but that didn't work, does anyone else have any ideas?

4

2 回答 2

6

好吧,这个问题已经以不同的方式提出,问题的主题是;

如何排除构建任务的子任务?

1. gradle build -x 测试

从 CLI 执行 gradle build 命令时,上述指令很有帮助;这排除了测试任务,但我们想在 build.gradle 文件中以编程方式排除测试任务。在下面查看相应问题的答案。

2. check.dependsOn -= 测试

将此小脚本复制到您的 build.gradle 文件中。现在,当您从 CLI 执行gradle build时,您的测试根本不会运行。

干杯!

于 2014-06-10T10:19:09.640 回答
2

You could try to disable the task only if a build task is present... Something like:

project(":serverTest").test.onlyIf { !gradle.taskGraph.hasTask(":shared:build") }
于 2013-02-11T20:28:36.343 回答