Gradle M6 and "Forked groovyc returned error code: 1" when using spock?

Actually, some of my observations were wrong. We have to consider two cases:

  1. groovyc throws an exception

This is what happened when you used Groovy with an incompatible Spock version. In this case, groovyc doesn’t log anything to std err. This is something that needs to be improved on the Groovy side.

  1. groovyc reports a compile error In this case, groovyc prints its output to std err, and Gradle reports it just fine.

The reason why 2. doesn’t work for you is that your build script contains a mistake. You add all ‘gradleApi()’ Jars to the ‘groovy’ configuration (which is the class path for executing groovyc). For some reason this leads to the output being lost. Here is a correct dependency declaration:

dependencies {
  groovy localGroovy()
  compile gradleApi()
}

This will solve your problem.