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


(Matias Bjarland) #1

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:

gradle-m6-spock

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

nadurra:gradle-m6-spock mbjarland$ gradle clean build
:clean
:compileJava UP-TO-DATE
:compileGroovy
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:compileTestGroovy
  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.
  BUILD FAILED
  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(ExecuteActionsTaskExecuter.java:71)  14:12:53.032 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:48)  14:12:53.038 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34)  14:12:53.039 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)  14:12:53.040 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)  14:12:53.040 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)  14:12:53.040 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)  14:12:53.041 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)  14:12:53.041 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)  14:12:53.042 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:243)  14:12:53.042 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:192)  14:12:53.044 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:177)  14:12:53.045 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:83)  14:12:53.045 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:36)  14:12:53.045 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:70)  14:12:53.046 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter.access$300(DefaultBuildExecuter.java:23)  14:12:53.046 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:80)  14:12:53.047 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)  14:12:53.047 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:70)  14:12:53.048 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:63)  14:12:53.048 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:157)  14:12:53.060 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:112)  14:12:53.060 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:80)  14:12:53.061 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:42)  14:12:53.062 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:28)  14:12:53.063 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:32)  14:12:53.063 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:21)  14:12:53.064 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:233)  14:12:53.064 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:217)  14:12:53.065 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.Main.doAction(Main.java:48)  14:12:53.065 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:53)  14:12:53.065 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:51)  14:12:53.066 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.Execution.execute(Execution.java:28)  14:12:53.067 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.exec.EntryPoint.run(EntryPoint.java:39)  14:12:53.067 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.Main.main(Main.java:39)  14:12:53.068 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:51)  14:12:53.068 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:33)  14:12:53.069 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.launcher.GradleMain.main(GradleMain.java:24)  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 org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)  14:12:53.070 [ERROR] [org.gradle.BuildExceptionReporter]  at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)  14:12:53.071 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:71)  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(ConfigureUtil.java:136)  14:12:53.072 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:85)  14:12:53.073 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.util.ConfigureUtil$configure.call(Unknown 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$execute.call(Unknown 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(IncrementalJavaSourceCompiler.java:73)  14:12:53.075 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.tasks.compile.GroovyCompile.compile(GroovyCompile.java:60)  14:12:53.076 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:158)  14:12:53.076 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:93)  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(AnnotationProcessingTaskFactory.java:129)  14:12:53.078 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$2.execute(AnnotationProcessingTaskFactory.java:127)  14:12:53.079 [ERROR] [org.gradle.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:63)  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.


(Matias Bjarland) #2

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

dependencies {
  groovy
    gradleApi()
  testCompile 'org.spockframework:spock-core:0.5-groovy-1.7'
}

to

dependencies {
  groovy
    gradleApi()
  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.

(Matias Bjarland) #3

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.


(Peter Niederwieser) #4

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.


(Matias Bjarland) #5

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?


(Peter Niederwieser) #6

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.


(Matias Bjarland) #7

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?


(Peter Niederwieser) #8

Unfortunately, only moderators can.


(Erick Dovale) #9

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.


(Peter Niederwieser) #10

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).


(Erick Dovale) #11

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.

Cheers

Erick.


(Matias Bjarland) #12

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?


(Peter Niederwieser) #13

I’ve just answered on the Spock list.