@Immutable Transform :compileTestGroovy FAILED: Error exists in the bytecode

The Spock test passes in Eclipse but blows up using Gradle with reason: Error exists in the bytecode Gradle: 2.0 Groovy: 2.3.6

import groovy.transform.Immutable
class ImmutablePath{
 List<ImmutableLine> segments = []
  import spock.lang.Specification
  class ImmutablePathTest extends Specification {
 ImmutablePath path
    def setup() {
  def lines = []
  ImmutablePoint p1 = new ImmutablePoint(x:0,y:0)
  ImmutablePoint p2 = new ImmutablePoint(x:3,y:0)
  ImmutablePoint p3 = new ImmutablePoint(x:0,y:4)
  lines << new ImmutableLine(start:p1, end:p2)
  lines << new ImmutableLine(start:p2, end:p3)
  lines << new ImmutableLine(start:p3, end:p1)
      path = new ImmutablePath(segments:lines)
Gradle Blows Up Here
FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':compileTestGroovy'.
> Bad <init> method call from inside of a branch
Exception Details:
    ImmutablePath.<init>(Ljava/util/List;)V @99: invokespecial
    Error exists in the bytecode
    0x0000000: b800 204d 04bd 0004 5903 05bd 0004 5903
    0x0000010: 12f6 5359 042b 53b8 00da 12dc b800 4bc0
    0x0000020: 00dc 12dc b800 4f53 5910 ff12 02b8 00e8
    0x0000030: 2a5f ab00 0000 0055 0000 0003 93eb 101e
    0x0000040: 0000 0022 0000 9b75 0000 0037 61fb 9e66
    0x0000050: 0000 0040 5f5a 5903 3212 dcb8 004b c000
    0x0000060: dc5f 57b7 00ea a700 2b5f 5a57 b700 eba7
    0x0000070: 0022 5f5a 5903 3212 5eb8 004b c000 5e5f
    0x0000080: 57b7 00ee a700 0dbb 00f0 5912 f2b7 00f5
    0x0000090: bf57 b1
  Stackmap Table:

It’s unlikely that the problem is on Gradle’s side. The Eclipse Groovy compiler is not quite the same as the official Groovy compiler. Make sure to try with ‘org.spockframework:spock-core:1.0-groovy-2.3-SNAPSHOT’ from ‘https://oss.sonatype.org/content/repositories/snapshots/’.

I modified my build.gradle file according to your suggestion. Now the

import groovy.transform.Immutable

produces error:

Multiple markers at this line
 - Groovy:Unexpected problem with AST transform: The Spock compiler plugin
   cannot execute because Spock 1.0.0-groovy-2.3-SNAPSHOT is not compatible with Groovy
   2.1.8. For more information, see http://versioninfo.spockframework.org
 - Groovy:@Immutable processor doesn't know how to handle field 'start' of type
   'ImmutablePoint' while compiling class ImmutableLine.
 - Groovy:@Immutable processor doesn't know how to handle field 'end' of type
   'ImmutablePoint' while compiling class ImmutableLine.

So you are using Groovy 2.1.8, not 2.3.6. For that you need ‘spock-core-1.0-groovy-2.0-SNAPSHOT’. Or you have multiple Groovy versions on the class path, in which case you should get rid of all but one.

Groovy thinks I’m running 2.1.8, but I’m in fact still running 2.3.6. This is what’s installed on my machine (the only version) and also what’s in my build.gradle dependencies. Out of the box eclipse uses 2.3.3 for Groovy projects so I don’t understand what Groovy’s talking about.

You definitely have 2.1.8 on the class path. This could either be added by the Groovy Eclipse plugin, or be on the user-defined class path. Anyway, I’d first concentrate on finding a solution for the command line build.