Skip to content

#patch: Compile the Spock extension statically so it loads on Groovy 6 - #207

Open
ErkoRisthein wants to merge 1 commit into
codedabble-dev:mainfrom
ErkoRisthein:groovy-6-compile-static
Open

ErkoRisthein wants to merge 1 commit into
codedabble-dev:mainfrom
ErkoRisthein:groovy-6-compile-static

Conversation

@ErkoRisthein

Copy link
Copy Markdown
Contributor

@EnableSnapshots can't start on Groovy 6, so every Spock spec that uses it fails at initialization:

org.spockframework.runtime.extension.ExtensionException: Failed to instantiate extension 'au.com.origin.snapshots.spock.SnapshotExtension'
Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/callsite/CallSiteArray

The module is compiled with dynamic Groovy 2.5.8, so its classes carry call site caches built on CallSiteArray, and Groovy 6 no longer has that class.

Change

  • @CompileStatic on SnapshotExtension and SnapshotMethodInterceptor, so the compiled classes no longer reference CallSiteArray. The module still compiles against Groovy 2.5.8 and Spock 1.3.
  • Plain for loops replace eachWithIndex and the spread operator, so the static code doesn't bind to DefaultGroovyMethods signatures at compile time.
  • log is typed as Logger, which static compilation needs.
  • New GroovyRuntimeCompatibilitySpec fails if an extension class references CallSiteArray. The module's tests run on Groovy 2.5, so this checks the bytecode rather than running on Groovy 6.

Verification

./gradlew :java-snapshot-testing-spock:build passes.

I also published the branch with publishToMavenLocal and ran a downstream project's snapshot tests against it: 7 test classes (Spock and JUnit 5), 34 tests, compiled with the Groovy version in the table.

Library Groovy Spock Result
4.2.1 6.0.0 2.5-groovy-6.0 The 2 Spock classes fail to initialize with the error above
this branch 6.0.0 2.5-groovy-6.0 34 pass
this branch 5.1.3 2.5-groovy-5.0 34 pass

Static compilation binds method calls at compile time, so the risk to check is a Spock API that differs between 1.3 and later versions. Spock 1.3 is covered by the module's tests and 2.5 by the runs above. I did not run other Spock 2.x versions.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the Spock extension’s Groovy 6 compatibility changes.

No open issues 🎉

What changed in this PR

Updates the Spock snapshot extension to load on Groovy 6 by removing dynamically compiled references to the deleted CallSiteArray class, while retaining the existing Groovy 2.5.8 and Spock 1.3 compilation baseline.

Changes:

  • Statically compiles both extension classes and adds explicit types where needed.
  • Replaces dynamic iteration and spread operations with plain loops.
  • Adds a bytecode regression test that checks for CallSiteArray references.
File Description
java-snapshot-testing-spock/​src/​test/​groovy/​au/​com/​origin/​snapshots/​spock/​GroovyRuntimeCompatibilitySpec.groovy Checks compiled extension classes for references to the removed call-site cache.
java-snapshot-testing-spock/​src/​main/​groovy/​au/​com/​origin/​snapshots/​spock/​SnapshotMethodInterceptor.groovy Adds static compilation, explicit types, and indexed parameter iteration.
java-snapshot-testing-spock/​src/​main/​groovy/​au/​com/​origin/​snapshots/​spock/​SnapshotExtension.groovy Adds static compilation and registers feature interceptors through a plain loop.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants