Skip to content

Commit 264f45f

Browse files
authored
Restore compatibility with Java 11 (2025.1.1) (#484)
Effectively a cherry-pick of #485 for the upcoming patch release, 2025.1.1
1 parent bffbdd5 commit 264f45f

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

library/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
12
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
23
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
34

@@ -100,9 +101,15 @@ publishing {
100101
}
101102
}
102103

104+
tasks.named("compileJava", JavaCompile::class) {
105+
sourceCompatibility = JavaVersion.VERSION_11.majorVersion
106+
targetCompatibility = JavaVersion.VERSION_11.majorVersion
107+
}
108+
103109
tasks.named("compileKotlin", KotlinCompile::class) {
104110
compilerOptions {
105111
languageVersion = KotlinVersion.KOTLIN_1_8
112+
jvmTarget = JvmTarget.JVM_11
106113
}
107114
}
108115

library/src/examplesTest/kotlin/com/gabrielfeo/develocity/api/example/gradle/ExampleGradleTaskTest.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.gabrielfeo.develocity.api.example.gradle
22

3+
import org.junit.jupiter.api.Assertions.assertFalse
34
import org.junit.jupiter.api.Assertions.assertTrue
45
import org.junit.jupiter.api.BeforeEach
56
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation
@@ -11,7 +12,6 @@ import java.nio.file.Path
1112
import com.gabrielfeo.develocity.api.example.copyFromResources
1213
import com.gabrielfeo.develocity.api.example.runInShell
1314
import kotlin.io.path.div
14-
import java.nio.file.Files
1515

1616
@TestMethodOrder(OrderAnnotation::class)
1717
class ExampleGradleTaskTest {
@@ -22,13 +22,11 @@ class ExampleGradleTaskTest {
2222
private val projectDir
2323
get() = tempDir / "examples/example-gradle-task"
2424

25-
private val initScriptPath
26-
get() = tempDir / ResourceInitScripts.FORCE_SNAPSHOT_LIBRARY
27-
2825
@BeforeEach
2926
fun setup() {
3027
copyFromResources("/examples", tempDir)
3128
copyFromResources("/${ResourceInitScripts.FORCE_SNAPSHOT_LIBRARY}", tempDir)
29+
copyFromResources("/${ResourceInitScripts.REQUIRE_JAVA_11_COMPATIBILITY}", tempDir)
3230
}
3331

3432
@Test
@@ -49,11 +47,18 @@ class ExampleGradleTaskTest {
4947
assertPerformanceMetricsOutput(output, user = user, period = "-14d")
5048
}
5149

50+
@Test
51+
fun testJavaVersionCompatibility() {
52+
val initScript = tempDir / ResourceInitScripts.REQUIRE_JAVA_11_COMPATIBILITY
53+
val output = runBuild("-p buildSrc :generateExternalPluginSpecBuilders -I '$initScript'").stdout
54+
assertFalse(Regex("""FAILED|Could not resolve|No matching variant""").containsMatchIn(output))
55+
}
56+
5257
private fun runBuild(gradleArgs: String) =
5358
runInShell(
5459
projectDir,
5560
"./gradlew --stacktrace --no-daemon",
56-
"-I $initScriptPath",
61+
"-I ${tempDir / ResourceInitScripts.FORCE_SNAPSHOT_LIBRARY}",
5762
gradleArgs,
5863
)
5964

library/src/examplesTest/kotlin/com/gabrielfeo/develocity/api/example/gradle/ResourceInitScripts.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ package com.gabrielfeo.develocity.api.example.gradle
22

33
object ResourceInitScripts {
44
const val FORCE_SNAPSHOT_LIBRARY = "force-snapshot-library.init.gradle.kts"
5+
const val REQUIRE_JAVA_11_COMPATIBILITY = "require-java-11-compatibility.init.gradle"
56
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
afterProject {
2+
it.java {
3+
sourceCompatibility = JavaVersion.VERSION_11
4+
targetCompatibility = JavaVersion.VERSION_11
5+
}
6+
it.tasks.named('compileKotlin') {
7+
compilerOptions {
8+
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)