2
votes

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?

2
I assume you have also declared defaultTasks for the root project? From what I can tell, only the defaultTasks of the default project (which is determined based on the directory that Gradle is invoked from) are considered.Peter Niederwieser
Do you always want to skip the serverTest:test task, or only sometimes?Hiery Nomus
@HieryNomus Always when I run it from the top levelGrammin
@PeterNiederwieser but even if I did set the defaultTasks on the root project wouldn't it still execute the same tasks as it is now in the serverTest project?Grammin
Well, if you set build as the default, that certainly includes test. What exactly are you trying to achieve?Peter Niederwieser

2 Answers

6
votes

Well this question has been asked in different ways , the main theme of the question is;

How to exclude sub tasks of build task?

1 . gradle build -x test

The above instruction is helpful while executing gradle build command from CLI; this exludes test task, but we want to exclude test task programmatically in build.gradle file. Look below the answer for the respective question.

2 . check.dependsOn -= test

Copy this small script in your build.gradle file. Now when you execute gradle build from CLI, your tests won't run at all.

Cheers !

2
votes

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") }