Since Gradle 2.11 we can specify the test framework to use when we initialise a project with the
init task. There is a new option for this task:
--test-framework. By default JUnit dependencies are added, but if we specify the value
spock the Spock libraries are included in the dependencies section of our
Let's run the
init task to create a Java project with Spock as test framework:
$ gradle init --type java-library --test-framework spock
Let's see the contents of the
build.gradle file that is generated:
* This build file was auto generated by running the Gradle 'init' task
* by 'mrhaki' at '2/12/16 8:54 AM' with Gradle 2.11
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://ift.tt/1o6tWKW
// Apply the java plugin to add support for Java
apply plugin: 'java'
// Apply the groovy plugin to also add support for Groovy (needed for Spock)
apply plugin: 'groovy'
// In this section you declare where to find the dependencies of your project
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
// In this section you declare the dependencies for your production and test code
// The production code uses the SLF4J logging API at compile time
// We use the latest groovy 2.x version for Spock testing
// Use the awesome Spock testing and specification framework even with Java
Notice in the
dependencies section that the Groovy and Spock dependencies are added.
Written with Gradle 2.11.