concept build in category gradle

appears as: build, builds, build, The build, builds
Gradle in Action - corrected 9052019

This is an excerpt from Manning's book Gradle in Action - corrected 9052019.

1.3.1. On-demand builds

The typical use case for on-demand automation is when a user triggers a build on his or her machine, as shown in figure 1.1. It’s common practice that a version control system (VCS) manages the versioning of the build definition and source code files.

$ gradle deployToLocalTomcat
:deployToLocalTomcat FAILED

FAILURE: Build failed with an exception.

* Where: Build file '/Users/benjamin/gradle-in-action/code/
 chapter5/cargo-configuration/build.gradle' line: 10

* What went wrong:
Execution failed for task ':deployToLocalTomcat'.
> Could not resolve all dependencies for configuration ':cargo'.
   > Could not find group:org.codehaus.cargo, module:cargo-core-
      uberjar, version:1.3.1.
     Required by:
         :cargo-configuration:unspecified
   > Could not find group:org.codehaus.cargo, module:cargo-ant,
      version:1.3.1.
     Required by:
         :cargo-configuration:unspecified

Gradle’s Java plugin does all of this heavy lifting for you. It introduces a standard directory structure for test source code and required resource files, integrates test code compilation and its execution into the build’s lifecycle, and plays well with almost all of the popular testing frameworks. This is a significant improvement over implementing the same functionality in an imperative build tool like Ant. You’d easily have to write 10 to 20 lines of code to set up a testing framework for your code. If that wasn’t enough, you’d have to copy the same code for every project that wants to use it.

Executing the build with gradle :repository:test reveals one shortcoming: the HTML report index page doesn’t contain all test results. This happens because the second run of the report generation overwrites the first one. Therefore, it only contains the JUnit and Spock test results. This can easily be fixed by merging the test results of both test tasks. The next listing shows how to create a new task of type org.gradle .api.tasks.testing.TestReport to generate the aggregate report.

Listing 7.6. Test report aggregation

To integrate this task into the build lifecycle, you added it as a dependent task to the verification task check, as shown in figure 7.7. Executing the task build will automatically aggregate the test reports.

Running gradle :repository:build on the command line will invoke the test tasks that run unit and integration tests. Mixing different types of tests in the same source folder might sound like a good idea at first. With an increasing number of test classes, the test sources in your project will become hard to navigate and differentiate. You’ll also have to teach every developer on your team to stick to the test class naming convention. If this pattern isn’t followed meticulously, a test class might be executed in an unintended phase of the build. As you learned, integration tests usually take longer to execute than unit tests, so this would be a significant drawback. With Gradle, you can do better. You can actually enforce your own conventions by separating unit and integration tests into different source sets.