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

There are two earlier posts which might or might not be related to this issue at:

compile groovy failing without apparent reason and Gradle not showing groovyc output

but as they are not identical I will post this separately and we’ll see where it lands.

I have a large multi-project build which started failing with very little information given to the caller when switching from M5 to M6. I have created a sample bare bones project which reproduces the error. It can be downloaded from s3 in zipped format at:


When executing a simple clean build cycle I get the following output:

nadurra:gradle-m6-spock mbjarland$ gradle clean build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:compileTestJava UP-TO-DATE
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':compileTestGroovy'.
Cause: Forked groovyc returned error code: 1
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  Total time: 9.905 secs

running with the debug switch gives the following (snipped for brevity):

  ...snip...  14:12:50.703 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':compileTestGroovy'.  14:12:50.705 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver] Resolving configuration ':groovyCopy'  14:12:50.706 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Skipping evicted #gradle-m6-spock;unspecified(groovyCopy).  14:12:53.009 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':compileTestGroovy'  14:12:53.019 [ERROR] [org.gradle.BuildExceptionReporter]

14:12:53.021 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.  14:12:53.021 [ERROR] [org.gradle.BuildExceptionReporter]

14:12:53.022 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:  14:12:53.022 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':compileTestGroovy'.  14:12:53.029 [ERROR] [org.gradle.BuildExceptionReporter] Cause: Forked groovyc returned error code: 1  14:12:53.029 [ERROR] [org.gradle.BuildExceptionReporter]

14:12:53.030 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:  14:12:53.031 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileTestGroovy'.  14:12:53.031 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(  14:12:53.032 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(  14:12:53.038 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(  14:12:53.039 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(  14:12:53.040 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(  14:12:53.040 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(  14:12:53.040 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(  14:12:53.041 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(  14:12:53.041 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(  14:12:53.042 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(  14:12:53.042 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(  14:12:53.044 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(  14:12:53.045 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultTaskGraphExecuter.execute(  14:12:53.045 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.SelectedTaskExecutionAction.execute(  14:12:53.045 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter.execute(  14:12:53.046 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter.access$300(  14:12:53.046 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter$2.proceed(  14:12:53.047 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DryRunBuildExecutionAction.execute(  14:12:53.047 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter.execute(  14:12:53.048 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter.execute(  14:12:53.048 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(  14:12:53.060 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.initialization.DefaultGradleLauncher.doBuild(  14:12:53.060 [ERROR] [org.gradle.BuildExceptionReporter]  at  14:12:53.061 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.cli.RunBuildAction.execute(  14:12:53.062 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.cli.RunBuildAction.execute(  14:12:53.063 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.ExceptionReportingAction.execute(  14:12:53.063 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.ExceptionReportingAction.execute(  14:12:53.064 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(  14:12:53.064 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(  14:12:53.065 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.Main.doAction(  14:12:53.065 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.EntryPoint$1.execute(  14:12:53.065 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.EntryPoint$1.execute(  14:12:53.066 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.Execution.execute(  14:12:53.067 [ERROR] [org.gradle.BuildExceptionReporter]  at  14:12:53.067 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.Main.main(  14:12:53.068 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.ProcessBootstrap.runNoExit(  14:12:53.068 [ERROR] [org.gradle.BuildExceptionReporter]  at  14:12:53.069 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.GradleMain.main(  14:12:53.069 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: : Forked groovyc returned error code: 1  14:12:53.070 [ERROR] [org.gradle.BuildExceptionReporter]  at  14:12:53.070 [ERROR] [org.gradle.BuildExceptionReporter]  at  14:12:53.071 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(  14:12:53.071 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.project.AntBuilderDelegate.nodeCompleted(DefaultIsolatedAntBuilder.groovy:140)  14:12:53.072 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.compile.AntGroovyCompiler$_execute_closure1.doCall(AntGroovyCompiler.groovy:66)  14:12:53.072 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.util.ConfigureUtil.configure(  14:12:53.072 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.util.ConfigureUtil.configure(  14:12:53.073 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.util.ConfigureUtil$ Source)  14:12:53.073 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.project.DefaultIsolatedAntBuilder.execute(DefaultIsolatedAntBuilder.groovy:101)  14:12:53.074 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.project.IsolatedAntBuilder$ Source)  14:12:53.074 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.compile.AntGroovyCompiler.execute(AntGroovyCompiler.groovy:63)  14:12:53.075 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.compile.IncrementalJavaSourceCompiler.execute(  14:12:53.075 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.tasks.compile.GroovyCompile.compile(  14:12:53.076 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.BeanDynamicObject.invokeMethod(  14:12:53.076 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(  14:12:53.077 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.tasks.compile.GroovyCompile_Decorated.invokeMethod(Unknown Source)  14:12:53.077 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)  14:12:53.078 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$2.execute(  14:12:53.078 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$2.execute(  14:12:53.079 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(  14:12:53.079 [ERROR] [org.gradle.BuildExceptionReporter]  ... 37 more  14:12:53.080 [ERROR] [org.gradle.BuildExceptionReporter]

14:12:53.080 [LIFECYCLE] [org.gradle.BuildResultLogger]

14:12:53.081 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED  14:12:53.081 [LIFECYCLE] [org.gradle.BuildResultLogger]

14:12:53.082 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 9.97 secs  

So we have a failing groovy compile with, from what I can see, no way of knowing what actually broke the build?

As a side note: The latest snapshots of the gradle-artifactory plugin from jfrog which we use in a number of projects started requiring M6 (it’s built against org/codehaus/groovy/runtime/BytecodeInterface8.class which was introduced in groovy 1.8.x…). So as far as I understand we are more or less forced to switch to M6 which in turn causes the above issues. This leaves me stuck between a rock and a hard place. Alternatives would be to figure out how to reference a not-most-up-to-date snapshot version of the plugin (an earlier version used to work with M5) or to use a groovy version separate from the gradle provided one. Not sure how to accomplish the latter in a plugin project which uses the gradleApi() call and not sure how to accomplish the former using the gradle snapshot dependency syntax. So one of these solutions would also solve my immediate problem.

I am fairly stomped on this issue and looking at the linked threads it seems probable that others might be running into this also. Any help much appreciated.

A quick update on this. If I change the dependency declaration from:

dependencies {
  testCompile 'org.spockframework:spock-core:0.5-groovy-1.7'


dependencies {
  testCompile 'org.spockframework:spock-core:0.6-groovy-1.8-SNAPSHOT'

then the compile works.

There is a catch though.

If, after changing the depencency above, we introduce a compile error in the spock test, we get back to the “Forked groovyc returned error code: 1” message. In other words, the initial error might have been caused by the fact that M6 ships with groovy 1.8.x and that this forces (does it?) us to use the 1.8 compatible spock version, but even after using the correct version we lose the information on what the compile error actually is.

This leaves me with two questions:

  1. How do we fix the “groovyc swallows all useful information” issue? 2. What is the correct way to use spock with M6? Are we forced to move to the snapshot 1.8 release of spock because of the updated gradle-shipped groovy version? Keeping in mind that the project in question is a plugin project and uses the gradleApi() call.

Any news on this issue? This is fairly severe for my project. All the reporting, dependency resolution, extensibility etc is somewhat secondary to actually finding out what part of your code broke the build. Not getting this information is a blocker. This used to work in M5 and now seems broken in M6.

At the same time the artifactory guys at jfrog are releasing a new release version of their artifactory-gradle plugin (today or tomorrow according to a conversation yesterday) which will now only work with M6. And as far as I understand it is not possible to point gradle at an older snapshot (one which works with M5).

Result: We either don’t use the artifactory plugin at all (undesirable), use M5 and manually download an old version of the plugin to disk and hack it onto the buildscript classpath, or we move to M6 and have no idea where errors occur when we have them in our unit tests.

Any help or pointers much appreciated.

A few pointers:

  • The issue that Gradle doesn’t print groovyc output is unrelated to Spock. * Gradle runs groovyc in fork mode by default, and groovyc prints its output to std err. For some reason this output is not shown in m6.

  • Forking can be turned off with ‘compileGroovy.groovyOptions.fork = false’. Then groovyc output will appear as expected. However, this mode has other limitations. For example, Groovy compiler plugins (and therefore Spock) apparently don’t work. * If you write Gradle plugins in Groovy, you have to compile them against the same major Groovy version as the one that’s used by Gradle at runtime. From m6 onwards this means 1.8.x. For testing Groovy 1.8.x code with Spock, you have to use spock-core-groovy-1.8-SNAPSHOT. If you prefer, you can use a unique snapshot.

Thank you for the reply and pointers. Much appreciated!

I have hacked my way to using an older snapshot of the artifactory plugin. This allows me to stay on M5 for the time being. Any idea of the schedule for fixing the missing stderr output from groovyc?

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.

Perfect! Thank you! This will finally unblock me and allow me to move to M6. Been sitting in a mexican standoff between the artifactory plugin and various features of M6 for a while.

[edit] how do I mark this question as answered?

Unfortunately, only moderators can.

I have experienced this problem when dependencies are not found (another gradle issue.). In this case there is no compilation error captured by gradle at all. Instead the message above is shown. When I compile using groovyc ant task directly from ant I can se the classnotfound exceptions.

I have experienced this problem when dependencies are not found (another gradle issue.).

In this case there is no compilation error captured by gradle at all.

A ClassNotFoundException means that groovyc has thrown an exception, not that it has reported a compilation error. So we are back to 1. above.

When I compile using groovyc ant task directly from ant I can se the classnotfound exceptions.

Probably because you don’t set fork=true (which is Gradle’s default).

Hi Peter, thanks for your quick reply. In fact, I did set the fork flag to true and you are right, it was not a classcast exception; instead it is a MultipleCompilationErrorsException or something like that.

To be completely honest, I am not sure my claims are true. It has behaved very inconsistently for me since I upgraded to M6. Sometimes I see the meaningless error message and some others I see ant output like:

[ant:groovyc] foo comming out of gradle.



Peter, this is horribly off topic but as I failed to figure out a better way to ask you: is the new spock Unroll syntax (discussed here) with ‘@Unroll def “method with #param”’ available in a snapshot somewhere?

I’ve just answered on the Spock list.