Skip to content

Commit 4796efd

Browse files
authored
Restore compatibility with Java 11 (#485)
Addresses variant resolution error demonstrated in [eBay/metrics-for-develocity-plugin#77][1] ([job][2]). Java 17 was introduced as target in upgrade to Gradle 9 (#454). ``` > Could not resolve all files for configuration ':compileClasspath'. > Could not resolve com.gabrielfeo:develocity-api-kotlin:2025.1.0. Required by: root project : > No matching variant of com.gabrielfeo:develocity-api-kotlin:2025.1.0 was found. The consumer was configured to find a library for use during compile-time, compatible with Java 11, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.11.1', attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but: Configuration cache entry discarded due to serialization error. - Variant 'apiElements' declares a library for use during compile-time, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm': - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11 - Other compatible attribute: - Doesn't say anything about org.gradle.plugin.api-version (required '8.11.1') - Variant 'javadocElements' declares a component for use during runtime, and its dependencies declared externally: - Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes: - Doesn't say anything about its elements (required them preferably in the form of class files) - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs) - Doesn't say anything about its target Java version (required compatibility with Java 11) - Doesn't say anything about org.gradle.plugin.api-version (required '8.11.1') - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm') - Variant 'runtimeElements' declares a library for use during runtime, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm': - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11 - Other compatible attribute: - Doesn't say anything about org.gradle.plugin.api-version (required '8.11.1') - Variant 'sourcesElements' declares a component for use during runtime, and its dependencies declared externally: - Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes: - Doesn't say anything about its elements (required them preferably in the form of class files) - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs) - Doesn't say anything about its target Java version (required compatibility with Java 11) - Doesn't say anything about org.gradle.plugin.api-version (required '8.11.1') - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm') ``` [1]: eBay/metrics-for-develocity-plugin#77 [2]: https://github.com/eBay/metrics-for-develocity-plugin/actions/runs/17635723239/job/50111470306?pr=77
1 parent fce617f commit 4796efd

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
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: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.gabrielfeo.develocity.api.example.gradle
22

3-
import com.gabrielfeo.develocity.api.example.BuildStartTime
3+
import org.junit.jupiter.api.Assertions.assertFalse
44
import org.junit.jupiter.api.Assertions.assertTrue
55
import org.junit.jupiter.api.BeforeEach
66
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation
@@ -9,10 +9,10 @@ import org.junit.jupiter.api.TestMethodOrder
99
import org.junit.jupiter.api.Test
1010
import org.junit.jupiter.api.io.TempDir
1111
import java.nio.file.Path
12+
import com.gabrielfeo.develocity.api.example.BuildStartTime
1213
import com.gabrielfeo.develocity.api.example.copyFromResources
1314
import com.gabrielfeo.develocity.api.example.runInShell
1415
import kotlin.io.path.div
15-
import java.nio.file.Files
1616

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

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

3533
@Test
@@ -50,11 +48,18 @@ class ExampleGradleTaskTest {
5048
assertPerformanceMetricsOutput(output, user = "runner", period = BuildStartTime.RECENT)
5149
}
5250

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

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)