# spock-example: A Runnable Starting Point for Spock Specifications

> spock-example is an Apache-2.0 licensed project of example Spock specifications with working Gradle and Maven builds, showing Spock 2.0 on the JUnit Platform, with branches kept for the Spock 1.x and Java 8 setups. It suits a Java or Groovy developer writing their first Spock test.

**spockframework/spock-example** — Spock example specifications along with ready-to-go Gradle and Maven builds

- Repository: https://github.com/spockframework/spock-example
- Website: http://spockframework.org
- Stars: 787 · Forks: 505
- Language: Groovy
- License: Apache-2.0
- Published: 2026-10-20 · Updated: 2026-10-20 · Language: en
- Canonical page: https://hysenlabs.com/projects/spockframework-spock-example

## An example project whose purpose is to be copied

The stated purpose of this project is to help you get started with Spock, and the mechanism is that it includes several example specifications together with build scripts for Gradle and Maven. It also makes it easy to create an Eclipse or IDEA project, so you can run the example specs from inside your IDE rather than only from a terminal. That is the design of a starter project rather than a framework: the value is in the shape of the files, not in the specifications themselves. The repository is licensed under Apache-2.0, its primary language is Groovy, and the project sits under the spockframework organisation, which also maintains the framework and its documentation. The default branch is master, the last push was on 2026-10-17, and there are no GitHub releases, so there is no version to pin and the master branch is the current state of the example.

## Two build systems, one set of specifications

Both build files are in the repository root, build.gradle for Gradle and pom.xml for Maven, and both produce the same result. The promise is that all builds, Gradle and Maven alike, will automatically download all required dependencies, compile the project and finally run the example specs. That single command is the whole tutorial. The Gradle build goes one step further by bootstrapping itself, which the documentation describes as alleviating the need to have a build tool preinstalled, so a machine with only a JDK can run the Gradle build. The Maven route relies on the wrapper in the same way, with mvnw and mvnw.cmd at the root alongside gradlew and gradlew.bat, so neither build tool needs to be on the machine either.

## Running the specs, and where the downloads land

Both builds are invoked with a clean and a test target.

```bash
./gradlew clean test
```

```bash
./mvnw clean test
```

The two download locations differ and it is worth knowing which is which. With Gradle, downloaded files including the Gradle distribution itself are stored in the Gradle user home directory, typically user_home/.gradle. With Maven, downloaded files go to the local Maven repository, typically user_home/.m2/repository. That difference matters when you are working in a restricted environment or a container with a small home directory, since the Gradle case pulls the whole distribution into the cache rather than only the dependencies.

## The version choices behind the Java 17 requirement

The prerequisites are a JDK 17 or higher, the Maven wrapper for Maven and the Gradle wrapper for Gradle, and the reason for the Java 17 floor is spelled out in a note. Spock supports Java 8, but Groovy 5.0 requires Java 11 or newer and Gradle 9 requires Java 17 or newer, so for simplicity the example uses Java 17. If you need an older Java version, the documentation points at using an older Gradle version such as Gradle 8.x for Java 8 and onwards, and at a java-8 branch that holds the last state of the example built for Java 8. The requirement therefore comes from the toolchain the example targets rather than from Spock itself, which is a distinction worth making before you conclude that Spock needs Java 17.

## Spock 2.0 on the JUnit Platform, and the branch for Spock 1.x

A second note covers the framework version. This example shows the usage of Spock 2.0, which uses the JUnit Platform, and anyone who wants to see Spock 1.x with JUnit 4 up and running is pointed at a spock-1.x branch. That parallel maintenance is the practical value of the example project. Test frameworks move underneath you, and when Spock moved from JUnit 4 to the JUnit Platform, the way you ran a specification, the way the runner discovered it and the way you configured the build all changed with it. Having a repository where both configurations exist, with the same example specifications in each, is a faster way to see what actually changed than reading release notes. The two branches are described as holding the last state of the example for their respective combinations, which is exactly what you want when you are deciding which side of a migration you are on.

## Getting the project into your IDE

The IDE instructions are short because the project is laid out to be importable. For Eclipse, the documentation points at the Buildship plugin, which is what lets Eclipse import and drive a Gradle build, and says to install it if you want to use Gradle as the build tool. For IntelliJ IDEA, the instruction is simply to open the project directory and let it auto-detect the project settings. The Gradle side therefore needs one extra step on Eclipse, which is the usual cost of using a build tool that is not the IDE's own, and the Maven side needs nothing beyond the import that the IDE already does.

## What the repository contains and where to go next

The root holds both build systems and the wrappers, plus a build.xml, ivy.xml and ivysettings.xml for the Ant and Ivy route, a settings.gradle, and a .mvn directory for Maven configuration, with the source under src/. The presence of the Ant and Ivy files alongside Gradle and Maven tells you how many build systems this project has had to accommodate over the years, and how the example has been kept runnable on each. The documentation then points at the resources worth having open: the Spock homepage, the main documentation at docs.spockframework.org, the Spock in the Groovy web console page, the Stack Overflow tag, the Gitter chat, the GitHub discussion group and the issue tracker, plus the Gradle and Groovy homepages. The readme closes by directing comments and questions to the discussion group and signs off with happy spec'ing, from the Spock Framework Team.

## Conclusion

spock-example fits a developer who wants to see a Spock specification run before adopting the framework, and who wants a build that works with either Gradle or Maven. It is the wrong place to look for the framework itself, since the specifications live in the spock repository, and the wrong choice if you are on Java 8, where the current branch will not run and you need the java-8 branch. Before you start, check the Spock version your project uses, because this example targets 2.0 on the JUnit Platform while the 1.x branch is the one built on JUnit 4.

## FAQ

### What is spock-example for?

It helps you get started with Spock. It contains several example specifications and build scripts for Gradle and Maven, and it is easy to import as an Eclipse or IDEA project so you can run the example specs from your IDE.

### How do I build and run the example specs?

Run ./gradlew clean test or ./mvnw clean test from the project root. Both builds download the required dependencies, compile the project and run the example specs, and neither requires the build tool to be installed because the wrappers are included.

### Why does the example need Java 17?

Spock supports Java 8, but Groovy 5.0 requires Java 11 or newer and Gradle 9 requires Java 17 or newer, so the example uses Java 17 for simplicity. For an older Java, use an older Gradle such as 8.x and the java-8 branch.

### How do I see Spock 1.x with JUnit 4 instead of Spock 2.0?

The spock-1.x branch holds the example built for Spock 1.x with JUnit 4, while the master branch shows Spock 2.0 on the JUnit Platform.

### Can I open the example in Eclipse or IntelliJ IDEA?

Yes. For Eclipse, install the Buildship plugin if you want to use Gradle as the build tool. For IntelliJ IDEA, open the project directory and it auto-detects the project settings.

## Sources

- [Issues](https://github.com/spockframework/spock-example/issues)
- [License: Apache-2.0](https://github.com/spockframework/spock-example/blob/master/LICENSE)
- [Project website](http://spockframework.org)
- [README](https://github.com/spockframework/spock-example/blob/master/README.md)
- [spockframework/spock-example on GitHub](https://github.com/spockframework/spock-example)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/spockframework-spock-example
