How to run Spock tests for Java project with eclipse and gradle?

I’m facing troubles with this test execution. I’ve followed this tutorial: in order to configure my project. But when I run I got the following exception:

Class not found spock.tests.CustomerReaderSpec
java.lang.ClassNotFoundException: spock.tests.CustomerReaderSpec at at
java.lang.ClassLoader.loadClass( at
sun.misc.Launcher$AppClassLoader.loadClass( at

I don’t know why, because the class is under the following folder, as you can see:

enter image description here

Here’s my build.gradle:

apply plugin: 'groovy'
apply plugin: 'eclipse'

repositories {

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.0.5'

    implementation ''

    compile group: '', name: 'spring-data-jpa', version: '2.0.2.RELEASE'
    compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.1.Final'



task runScript (dependsOn: 'classes', type: JavaExec) {
    main = 'myscript'
    classpath = sourceSets.main.runtimeClasspath

test {
    useJUnit {
        includeCategories 'spock.tests.UnitTest'
    testLogging {
        showStandardStreams = true

What could be wrong with it?


About the tools.

I’m using:

Spring Tool Suite 
Version: 3.9.2.RELEASE
Platform: Eclipse Oxygen.2 (4.7.2)

Plugin for groovy:
Eclipse Groovy Development Tools
Version: 2.9.2.xx-201712201854-e47

Plugin for gradle:
Eclipse buildship
Version: 2.1.2.v20170807-1324

You can clone the project from here:

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

2 problems I can see in your sample project:

1) CustomerReaderSpec is missing “package spock.tests” at the top

2) Dependency “org.springframework:spring-test:5.0.2.RELEASE” is needed in testCompile

Also, be sure the Groovy compiler you have selected for your workspace (Window > Preferences > Groovy > Compiler) matches — at least major and minor — the version of groovy-all dependency you are using.

With those changes, I was able to run the spock test.