Skip to content

Commit

Permalink
Add Java 21 (#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonard84 authored Oct 11, 2023
1 parent 9b1e644 commit 3280ec0
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-jdks/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runs:
uses: actions/setup-java@v3
if: inputs.additional-java-version != 8 && inputs.additional-java-version != 17
with:
distribution: 'temurin'
distribution: ${{ inputs.additional-java-version == 21 && 'liberica' || 'temurin' }}
java-version: ${{ inputs.additional-java-version }}
- name: 'Prepare JDK${{ inputs.additional-java-version }} env var'
shell: bash
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/branches-and-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ jobs:
matrix:
os: ['ubuntu-latest']
variant: ['2.5', '3.0', '4.0']
java: ['8', '11', '17']
java: ['8', '11', '17', '21']
exclude:
- os: 'ubuntu-latest'
variant: '2.5'
java: '17'
- os: 'ubuntu-latest'
variant: '2.5'
java: '21'
include:
- os: 'windows-latest'
variant: '2.5'
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ jobs:
matrix:
os: [ 'ubuntu-latest' ]
variant: ['2.5', '3.0', '4.0']
java: [ '8', '11', '17' ]
java: [ '8', '11', '17', '21' ]
exclude:
- os: 'ubuntu-latest'
variant: '2.5'
java: '17'
- os: 'ubuntu-latest'
variant: '2.5'
java: '21'
include:
- os: 'windows-latest'
variant: '2.5'
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ext {
baseVersion = "2.4"
snapshotVersion = true
milestone = 0
javaVersions = [8, 11, 17] // ensure that latest version is actually build on travis, otherwise no docs get published
javaVersions = [8, 11, 17, 21] // ensure that latest version is actually build on GH actions and added to gradle.properties, otherwise no docs get published
javaVersion = (System.getProperty("javaVersion") ?: 8) as int
variants = [2.5, 3.0, 4.0]
variant = System.getProperty("variant") as BigDecimal ?: variants.first()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

org.gradle.java.installations.auto-download=false
org.gradle.java.installations.fromEnv=JDK8,JDK11,JDK17
org.gradle.java.installations.fromEnv=JDK8,JDK11,JDK17,JDK21

org.gradle.parallel=true
org.gradle.caching=true
8 changes: 6 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ include "spock-junit4"
include "spock-testkit"

def variant = System.getProperty("variant") as BigDecimal ?: 2.5
def javaVersion = (System.getProperty("javaVersion") ?: 8) as int

if (variant == 2.5) {
//Remove once Groovy 2.5 support is dropped
include "spock-groovy2-compat"
Expand All @@ -110,13 +112,15 @@ if (variant == 2.5) {
}

// https://issues.apache.org/jira/projects/TAP5/issues/TAP5-2588
if (((System.getProperty("javaVersion") ?: 8) as int) == 8) {
if (javaVersion == 8) {
include "spock-tapestry"
}

include "spock-unitils"

include "spock-spring:boot2-test"
if (javaVersion <= 17) {
include "spock-spring:boot2-test"
}
include "spock-spring:spring3-test"
include "spock-spring:spring5-test"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.spockframework.mock.CannotCreateMockException;
import org.spockframework.util.ReflectionUtil;
import org.spockframework.util.ThreadSafe;
import spock.util.environment.Jvm;

import java.util.Collections;
import java.util.EnumSet;
Expand Down Expand Up @@ -60,6 +61,9 @@ public IMockabilityResult getMockability(IMockCreationSettings settings) {
if (!cglibAvailable) {
return () -> "The cglib-nodep library is missing on the class path.";
}
if(Jvm.getCurrent().isJava21Compatible()){
return () -> "Mocking with cglib is not supported on Java 21 or newer.";
}
return IMockabilityResult.MOCKABLE;
}
}
2 changes: 2 additions & 0 deletions spock-specs/mock-integration/mock-integration.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ codeGenerationLibraries.each { key, config ->
"--add-opens=java.base/java.lang=ALL-UNNAMED"
)
}
onlyIf { rootProject.ext.javaVersion < 21}
}
}
tasks.register("test${key.capitalize()}WithObjenesis", Test) {
Expand All @@ -61,6 +62,7 @@ codeGenerationLibraries.each { key, config ->
"--add-opens=java.base/java.lang=ALL-UNNAMED"
)
}
onlyIf { rootProject.ext.javaVersion < 21}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class MockingIntegrationSpec extends Specification {
}

@IgnoreIf({ TEST_TYPE == "plain" })
@IgnoreIf(
value = { jvm.java21Compatible && TEST_TYPE.contains("cglib") },
reason = "Cglib doesn't support running on Java 21+"
)
def "can mock class when cglib or byte-buddy are present"() {
given:
def list = Mock(ArrayList)
Expand All @@ -32,6 +36,10 @@ class MockingIntegrationSpec extends Specification {
}

@Requires({ TEST_TYPE == "plain" })
@IgnoreIf(
value = { jvm.java21Compatible && TEST_TYPE.contains("cglib") },
reason = "Cglib doesn't support running on Java 21+"
)
def "cannot mock class without cglib and byte-buddy"() {
when:
Mock(ArrayList)
Expand All @@ -41,6 +49,10 @@ class MockingIntegrationSpec extends Specification {
}

@IgnoreIf({ TEST_TYPE == "plain" })
@IgnoreIf(
value = { jvm.java21Compatible && TEST_TYPE.contains("cglib") },
reason = "Cglib doesn't support running on Java 21+"
)
def "can spy on class when cglib or byte-buddy are present"() {
given:
def list = Spy(ArrayList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@
package org.spockframework.mock.runtime

import org.spockframework.mock.CannotCreateMockException
import org.spockframework.runtime.extension.builtin.PreconditionContext
import spock.lang.IgnoreIf
import spock.lang.Requires
import spock.lang.Specification
import spock.mock.DetachedMockFactory
import spock.mock.MockMakers

import java.lang.reflect.Proxy
import java.util.concurrent.Callable

@IgnoreIf(
value = { jvm.java21Compatible },
reason = "Cglib doesn't support running on Java 21+"
)
class CglibMockMakerSpec extends Specification {

def "Verify ID and IMockMakerSettings"() {
Expand Down Expand Up @@ -77,4 +84,21 @@ class CglibMockMakerSpec extends Specification {
def ex = thrown(CannotCreateMockException)
ex.message == "Cannot create mock for class java.lang.StringBuilder. cglib: Cannot mock final classes."
}


@Requires(
value = { jvm.java21Compatible },
reason = "Cglib doesn't support running on Java 21+"
)
static class CglibMockMakerUnsupportedSpec extends Specification {

def "Mocking with cglib on Java 21+ will be rejected with useful error message."() {
when:
Mock(mockMaker: MockMakers.cglib, List)
then:
def ex = thrown(CannotCreateMockException)
ex.message == "Cannot create mock for interface java.util.List. cglib: Mocking with cglib is not supported on Java 21 or newer."
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class Test extends Bar {

@Requires({
jvm.java8 || jvm.java9 || jvm.java10 || jvm.java11 || jvm.java12 || jvm.java13 || jvm.java14 || jvm.java15 || jvm.java16 || jvm.java17 ||
jvm.isJavaVersion(18)
jvm.isJavaVersion(18) || jvm.java21
})
def "provides JVM information"() {
expect: true
Expand Down

0 comments on commit 3280ec0

Please sign in to comment.