Hassan Mushtaq
Hassan Mushtaq

Reputation: 31

gradle build not skipping (always invoking) integration test

Context of my application structure:

  1. Nothing on root, just settings.gradle and build.gradle with minimal dependency.
  2. There are many module/subproject, one of them named xyzintegrationtest (xyz is fake example name)
  3. the integrationtest module xyzintegrationtest has src/main, src/test and src/integrationtest
  4. The src/main and src/test are empty. src/intgerationtest has integration tests using junit.
  5. The project xyzintegrationtest has dependency on all projects (implicitly)
  6. The integrationtest build.gradle file has following task:

task integrationTest(type: Test) {
......
}

Now when I do gradle build (or gradlew build) on root project I expect all projects to compile, and all unit tests to run that are under src/test of each subproject. But it is also calling this integrationTest task, and making integration tests run as well. And more surprisingly it happens sporadically, not consistently. I even tried gradle build -x integrationTest, but it still runs.

So question is:

  1. Does gradle build run all tasks that are of type test? Then how can I have task that only runs when I invoke it explicitly.
  2. Is it bug in gradle if first one is not supposed to happen?
  3. Am I doing something wrong? Structure is pretty flat, all modules/sub-projects at same level, the task name is pretty clear with type:test.

Thanks.

Upvotes: 3

Views: 2825

Answers (1)

HELOX
HELOX

Reputation: 529

  1. If you have for example the java plugin applied and run the Gradle task test than yes, all test tasks will be executed. Your integrationtest running while specificaly excluding it has probably to do with the Gradle build lifcycle. You might have your code directely in the configuration block rather than in a execution block. So for example:

    task integrationTest(type: Test) {
        println 'This will print while in the configuration fase.'
        doLast {
            println 'This will print while the task is beeing executed.'
        }
    }
    

    If no configuration is required you can also do:

    task integrationTest(type: Test) << {
        println 'This will print while the task is beeing executed.'
    }
    

    This all can be found in the Build Scripting Basics chapter of the Gradle User Guide which is extremely useful if using Gradle.

  2. So if I understand your question and situation correctly this is probably not a bug in Gradle.

  3. See point 1, you seem to have mixed up the configuration and execution fase.

Upvotes: 1

Related Questions