Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running test task on gradle root project does not run test task on subprojects

In my multiproject I am running test task on root project and expecting that it will run test task on subprojects and produce a single test report. What I observe is that it never runs test task on subprojects. Is my expectation incorrect" DO I need to do any special configuration in my gradle scripts?

Note that I have no tests in my root project.

like image 303
Farrukh Najmi Avatar asked Jan 22 '16 17:01

Farrukh Najmi


People also ask

What is subprojects in Gradle?

The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency.

Does Gradle run tests in parallel by default?

Parallel execution Yet Gradle will only run one task at a time by default, regardless of the project structure (this will be improved soon). By using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects.

Does Gradle build run all tasks?

Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.

How do I run a Gradle test in a specific project?

The command gradle test will execute the test task in any subprojects, relative to the current working directory, that have that task. If you run the command from the root project directory, you’ll run test in api, shared, services:shared and services:webservice.

What is the difference between single project and multi project Gradle testing?

The first approach is similar to the single-project use case, but Gradle works slightly differently in the case of a multi-project build. The command gradle test will execute the test task in any subprojects, relative to the current working directory, that have that task.

Why can’t I run a Gradle task from a specific project folder?

When you’re using the Gradle wrapper, executing a task for a specific subproject by running Gradle from the subproject’s directory doesn’t work well because you have to specify the path to the wrapper script if you’re not in the project root.

What is root project in Gradle project path?

The root project is the only project in a path that is not specified by its name. The rest of a project path is a colon-separated sequence of project names, where the next project is a subproject of the previous project. You can see the project paths when running gradle projects as shown in identifying project structure section.


1 Answers

I think, this snippet from Gradle User Guide should help you out:

subprojects {
    apply plugin: 'java'

    // Disable the test report for the individual test task
    test {
        reports.html.enabled = false
    }
}

task testReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/allTests")
    // Include the results from the `test` task in all subprojects
    reportOn subprojects*.test
}
like image 165
KKishore Avatar answered Oct 19 '22 22:10

KKishore