Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ae24dce
Add Groovy 5 support (#2196)
Vampire Oct 8, 2025
897fabc
Review Feedback Vol. 1
Vampire Oct 22, 2025
e048f44
GroovyMockMetaClass: Groovy 5 uses getProperty() and setProperty() fo…
AndreasTu Oct 23, 2025
262446a
Remove work-around for building with Groovy 5 before 5.0.2
Vampire Oct 23, 2025
1b7cf69
Add a test that verifies consistency of field and property resolution…
Vampire Oct 23, 2025
f9eec57
Implement getProperty setProperty for Global mocks.
AndreasTu Oct 23, 2025
ec29d9c
Remove unnecessary error handling code, which is already handled by G…
AndreasTu Oct 23, 2025
b6b32d0
Fixup exception handling on MissingPropertyException
AndreasTu Oct 23, 2025
001fed4
Update spock-specs/src/test/groovy/org/spockframework/smoke/mock/Groo…
AndreasTu Oct 23, 2025
b6ac569
Update spock-specs/src/test/groovy/org/spockframework/smoke/mock/Groo…
AndreasTu Oct 23, 2025
46792ea
Update spock-specs/src/test/groovy/org/spockframework/smoke/mock/Groo…
AndreasTu Oct 23, 2025
691dc05
Update spock-specs/src/test/groovy/org/spockframework/smoke/mock/Groo…
AndreasTu Oct 23, 2025
eec4d32
Update spock-specs/src/test/groovy/org/spockframework/smoke/mock/Groo…
AndreasTu Oct 23, 2025
7f2e3e1
Update spock-specs/src/test/groovy/org/spockframework/smoke/mock/Groo…
AndreasTu Oct 23, 2025
7c4b833
Update spock-specs/src/test/groovy/org/spockframework/smoke/mock/Groo…
AndreasTu Oct 23, 2025
bb6f404
Fixed review finding.
AndreasTu Oct 23, 2025
5568cbe
Merge branch 'master' into vampire/groovy5
AndreasTu Oct 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ codecov:

comment:
layout: "reach, diff, flags, files"
after_n_builds: 18
after_n_builds: 24
10 changes: 10 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
matchCurrentValue: "/^4\\./",
allowedVersions: "(,5.0)"
},
{
matchPackageNames: ["/^org.apache.groovy:/"],
matchCurrentValue: "/^5\\./",
allowedVersions: "(,6.0)"
},
{
matchPackageNames: ["/^org.mockito:/"],
matchCurrentValue: "/^4\\./",
Expand All @@ -34,6 +39,11 @@
matchPackageNames: ["/^org.spockframework:spock-/"],
matchCurrentVersion: "/-groovy-4\\.0$/",
allowedVersions: "/-groovy-4\\.0$/"
},
{
matchPackageNames: ["/^org.spockframework:spock-/"],
matchCurrentVersion: "/-groovy-5\\.0$/",
allowedVersions: "/-groovy-5\\.0$/"
}
]
}
10 changes: 10 additions & 0 deletions .github/workflows/branches-and-prs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
- '2.5'
- '3.0'
- '4.0'
- '5.0'
java:
- '8'
- '11'
Expand All @@ -74,6 +75,9 @@ jobs:
- variant: '2.5'
java: '25'
os: 'ubuntu-latest'
- variant: '5.0'
java: '8'
os: 'ubuntu-latest'
include:
- variant: '2.5'
java: '8'
Expand All @@ -84,6 +88,9 @@ jobs:
- variant: '4.0'
java: '8'
os: 'windows-latest'
- variant: '5.0'
java: '11'
os: 'windows-latest'
- variant: '2.5'
java: '8'
os: 'macos-latest'
Expand All @@ -93,6 +100,9 @@ jobs:
- variant: '4.0'
java: '8'
os: 'macos-latest'
- variant: '5.0'
java: '11'
os: 'macos-latest'
steps:
- id: 'step-0'
name: 'Checkout Repository'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/codeql-analysis.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ workflow(
"--stacktrace",
"--no-build-cache",
"testClasses",
""""-Dvariant=${expr(Matrix.variant)}""""
""""-Dvariant=${expr(Matrix.variant)}"""",
""""-DjavaVersion=${expr("${Matrix.variant} == '5.0' && '11' || '${Matrix.axes.javaVersions.first()}'")}""""
).joinToString(" ")
)
uses(
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- '2.5'
- '3.0'
- '4.0'
- '5.0'
steps:
- id: 'step-0'
name: 'Checkout Repository'
Expand All @@ -52,7 +53,7 @@ jobs:
uses: 'github/codeql-action/init@v3'
- id: 'step-3'
name: 'Build Spock Classes'
run: './gradlew --stacktrace --no-build-cache testClasses "-Dvariant=${{ matrix.variant }}"'
run: './gradlew --stacktrace --no-build-cache testClasses "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.variant == ''5.0'' && ''11'' || ''8'' }}"'
- id: 'step-4'
name: 'Perform CodeQL Analysis'
uses: 'github/codeql-action/analyze@v3'
19 changes: 12 additions & 7 deletions .github/workflows/common.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,20 @@ val Matrix.Companion.full
operatingSystems = listOf("ubuntu-latest"),
variants = axes.variants,
javaVersions = axes.javaVersions + axes.additionalJavaTestVersions,
exclude = { (variant == "2.5") && (javaVersion!!.toInt() >= 17) },
exclude = {
((variant == "2.5") && (javaVersion!!.toInt() >= 17)) ||
((variant == "5.0") && (javaVersion!!.toInt() < 11))
},
includes = listOf("windows-latest", "macos-latest")
.map {
Matrix.Element(
operatingSystem = it,
javaVersion = axes.javaVersions.first()
)
.map { Matrix.Element(operatingSystem = it) }
.flatMap { element ->
axes.variants.map {
element.copy(
variant = it,
javaVersion = if (it == "5.0") "11" else axes.javaVersions.first()
)
}
}
.flatMap { element -> axes.variants.map { element.copy(variant = it) } }
)

val Matrix.Companion.axes by lazy {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: 'sudo apt update && sudo apt install --yes graphviz'
- id: 'step-3'
name: 'Build Docs'
run: './gradlew --stacktrace asciidoctor javadoc "-Dvariant=4.0" "-DjavaVersion=25"'
run: './gradlew --stacktrace asciidoctor javadoc "-Dvariant=5.0" "-DjavaVersion=25"'
- id: 'step-4'
name: 'Archive and upload docs'
uses: 'actions/upload-artifact@v4'
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- '2.5'
- '3.0'
- '4.0'
- '5.0'
java:
- '8'
- '11'
Expand All @@ -54,6 +55,9 @@ jobs:
- variant: '2.5'
java: '25'
os: 'ubuntu-latest'
- variant: '5.0'
java: '8'
os: 'ubuntu-latest'
include:
- variant: '2.5'
java: '8'
Expand All @@ -64,6 +68,9 @@ jobs:
- variant: '4.0'
java: '8'
os: 'windows-latest'
- variant: '5.0'
java: '11'
os: 'windows-latest'
- variant: '2.5'
java: '8'
os: 'macos-latest'
Expand All @@ -73,6 +80,9 @@ jobs:
- variant: '4.0'
java: '8'
os: 'macos-latest'
- variant: '5.0'
java: '11'
os: 'macos-latest'
steps:
- id: 'step-0'
name: 'Checkout Repository'
Expand Down Expand Up @@ -109,6 +119,7 @@ jobs:
- '2.5'
- '3.0'
- '4.0'
- '5.0'
java:
- '8'
os:
Expand Down Expand Up @@ -140,7 +151,7 @@ jobs:
strategy:
matrix:
variant:
- '4.0'
- '5.0'
java:
- '25'
os:
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ Functional tests for `spock-core` are located under https://github.spockframewor
=== Command Line Build

Spock is built with https://www.gradle.org[Gradle].
The only prerequisite for executing the build is an installation of JDK 8 and JDK 17.
The build itself must be run with JDK 17, but JDK 8 must be available via toolchain.
The only prerequisite for executing the build is an installation of JDK 11 and JDK 17.
The build itself must be run with JDK 17, but JDK 11 must be available via toolchain.
You can check if Gradle can locate the necessary JDKs by running `./gradlew javaToolchains`.
If gradle can't locate your JDK 8, you can make the location of the JDK 8 available via an environment variable called `JDK8`.
If Gradle can't locate your JDK 11, you can make the location of the JDK 11 available via an environment variable called `JDK11`.

After cloning the https://github.com/spockframework/spock[GitHub repository], cd into the top directory and execute `./gradlew build`. The build should succeed without any errors. `./gradlew tasks` lists the available tasks.
Always use the Gradle Wrapper (`gradlew` command) rather than your own Gradle installation.
Expand Down
14 changes: 8 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ https://groovyconsole.dev/[Groovy Web Console].
* The latest 2.x release version is *{spock-release-version}* ({spock-release-version}-groovy-2.5,
{spock-release-version}-groovy-3.0, {spock-release-version}-groovy-4.0), released on {spock-release-date}.
* The current development version is *{spock-snapshot-version}-SNAPSHOT*
({spock-snapshot-version}-groovy-2.5-SNAPSHOT, {spock-snapshot-version}-groovy-3.0-SNAPSHOT, {spock-snapshot-version}-groovy-4.0-SNAPSHOT).
({spock-snapshot-version}-groovy-2.5-SNAPSHOT, {spock-snapshot-version}-groovy-3.0-SNAPSHOT,
{spock-snapshot-version}-groovy-4.0-SNAPSHOT), {spock-snapshot-version}-groovy-5.0-SNAPSHOT).

*NOTE:* Spock 2.x is based on the JUnit 5 Platform and requires Java
8+/groovy-2.5+ (Groovy 3.0 or 4.0 is recommended, especially in projects using
8+/groovy-2.5+ (Groovy 3.0 or newer is recommended, especially in projects using
Java 12+).

Releases are available from
Expand Down Expand Up @@ -86,25 +87,26 @@ https://tapestry.apache.org/[Tapestry 5] IoC container.

==== Prerequisites

Spock needs both a JDK 8 and JDK 17+ installed.
Spock needs both a JDK 11 and JDK 17+ installed.

* JDK 8 is required to compile Spock via toolchains (automatic download is disabled).
* JDK 11 is required to compile Spock via toolchains (automatic download is disabled).
* The gradle build itself requires at least JDK 17 to run.

JDK locations must be made known to toolchains via `JDK<version>=<PATH>` environment
variable, e.g., `JDK8=/path/to/jdk8`.
variable if they are not in standard places recognized by Gradle, e.g. `JDK11=/path/to/jdk11`.

==== Supported versions

Spock is supported for Java version 8+.

Spock is supported for Groovy versions 2.5, 3.0, and 4.0.
Spock is supported for Groovy versions 2.5, 3.0, 4.0, and 5.0.

The tests are testing Spock with the specific versions (variants) of
Groovy and Java. Default Groovy version is 2.5.

The Groovy 3.0 and 4.0 variant should pass on all supported JDK versions,
Groovy 2.5 does not work with Java 17+:
Groovy 5.0 and newer does not work with Java <11:

....
./gradlew build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import java.time.Duration
class SpockBasePlugin implements Plugin<Project> {

@VisibleForTesting
public static final JavaLanguageVersion COMPILER_VERSION = JavaLanguageVersion.of(8)
public static final JavaLanguageVersion COMPILER_VERSION = JavaLanguageVersion.of(11)
public static final int COMPILER_RELEASE_VERSION = 8

void apply(Project project) {
applyPlugins(project)
Expand All @@ -65,6 +66,7 @@ class SpockBasePlugin implements Plugin<Project> {
comp.javaCompiler.set(javaToolchains.compilerFor {
it.languageVersion.set(COMPILER_VERSION)
})
comp.options.release.set(COMPILER_RELEASE_VERSION)
}
comp.options.encoding = 'UTF-8'
}
Expand Down
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ ext {
groovyVersion = libs.versions.groovy4.get()
minGroovyVersion = "4.0.0"
maxGroovyVersion = "4.9.99"
} else if (variant == 5.0) {
groovyGroup = "org.apache.groovy"
groovyVersion = libs.versions.groovy5.get()
minGroovyVersion = "5.0.0"
maxGroovyVersion = "5.9.99"
if (javaVersion < 11) {
throw new InvalidUserDataException("Groovy $variant is not compatible with Java $javaVersion")
}
} else {
throw new InvalidUserDataException("Unknown variant: $variant. Choose one of: $variants")
}
Expand Down
1 change: 1 addition & 0 deletions docs/release_notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ _This is a summary of the highlights of the milestone releases_
* Add <<extensions.adoc#spock-interceptors,feature-scoped interceptors>> spockPull:1844[]
* Add `@Snapshot` extension for <<extensions.adoc#snapshot-testing,snapshot testing>> spockPull:1873[]
* Add `!!` as <<spock_primer.adoc#opt-out-of-condition-handling,opt-out operator for assertions>> spockPull:1532[]
* Add support for Groovy 5.0 spockIssue:2196[]

=== Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ org.gradle.caching=true

javaVersionsList=8, 11, 17, 21, 25
additionalJavaTestVersionsList=
variantsList=2.5, 3.0, 4.0
variantsList=2.5, 3.0, 4.0, 5.0
kotlin.code.style=official
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ asciidoctorj = '3.0.0'
groovy2 = '2.5.23'
groovy3 = '3.0.25'
groovy4 = '4.0.29'
groovy5 = '5.0.2'
jacoco = '0.8.14'
junit = '5.14.0'
# The VersionRange used by OSGi to check compatibility with JUnit Platform.
Expand Down Expand Up @@ -46,3 +47,4 @@ workflows-kotlin-scriptingCompiler = { module = "org.jetbrains.kotlin:kotlin-scr
groovy-v2 = { module = "org.codehaus.groovy:groovy", version.ref="groovy2" }
groovy-v3 = { module = "org.codehaus.groovy:groovy", version.ref="groovy3" }
groovy-v4 = { module = "org.apache.groovy:groovy", version.ref="groovy4" }
groovy-v5 = { module = "org.apache.groovy:groovy", version.ref="groovy5" }
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,8 @@ private Expression transformRhsExpressionIfNecessary(DeclarationExpression declE
MethodCallExpression methodCallExpression = (MethodCallExpression)rightExpression;
if (methodCallExpression.isImplicitThis())
if (declExpr.isMultipleAssignmentDeclaration()) {
ArgumentListExpression argumentListExpression = (ArgumentListExpression)declExpr.getLeftExpression();
argumentListExpression.getExpressions().stream()
TupleExpression tupleExpression = (TupleExpression)declExpr.getLeftExpression();
tupleExpression.getExpressions().stream()
.filter(VariableExpression.class::isInstance)
.map(VariableExpression.class::cast)
.map(VariableExpression::getName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ public Object intercept(Object target, Method method, Object[] arguments, IRespo
throw new MissingMethodException((String)args[0],
mockConfiguration.getType(), new Object[]{args[1]}, false);
}
if (isMethod(method, "propertyMissing", String.class)) {
throw new MissingPropertyException((String)args[0], mockConfiguration.getType());
}


IMockMethod mockMethod = new StaticMockMethod(method, mockConfiguration.getExactType());
IMockInvocation invocation = new MockInvocation(mockObject, mockMethod, asList(args), realMethodInvoker);
IMockController controller = specification.getSpecificationContext().getMockController();
Expand Down
Loading