Skip to content

Commit 681c70d

Browse files
authored
feat: use java toolchain when generating SDL (#2058)
### 📝 Description when the toolchain used by kotlin/java compilation tasks generates classfiles with newer versions, running the task in-process (i.e. with `classLoaderIsolation`) results in a build failing with UnsupportedClassVersionError. switching to `processIsolation` and using (by default) the configured java toolchain should mitigate this ### 🔗 Related Issues not raised (can raise an issue if required)
1 parent 700f0ea commit 681c70d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

plugins/graphql-kotlin-gradle-plugin/src/main/kotlin/com/expediagroup/graphql/plugin/gradle/tasks/GraphQLGenerateSDLTask.kt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ package com.expediagroup.graphql.plugin.gradle.tasks
1919
import com.expediagroup.graphql.plugin.gradle.actions.GenerateSDLAction
2020
import org.gradle.api.file.ConfigurableFileCollection
2121
import org.gradle.api.file.RegularFileProperty
22+
import org.gradle.api.plugins.JavaPluginExtension
2223
import org.gradle.api.provider.ListProperty
24+
import org.gradle.api.provider.Property
2325
import org.gradle.api.tasks.Classpath
2426
import org.gradle.api.tasks.Input
27+
import org.gradle.api.tasks.Nested
2528
import org.gradle.api.tasks.Optional
2629
import org.gradle.api.tasks.OutputFile
2730
import org.gradle.api.tasks.SourceTask
2831
import org.gradle.api.tasks.TaskAction
2932
import org.gradle.api.tasks.options.Option
30-
import org.gradle.workers.ClassLoaderWorkerSpec
33+
import org.gradle.jvm.toolchain.JavaLauncher
34+
import org.gradle.jvm.toolchain.JavaToolchainService
35+
import org.gradle.workers.ProcessWorkerSpec
3136
import org.gradle.workers.WorkQueue
3237
import org.gradle.workers.WorkerExecutor
3338
import javax.inject.Inject
@@ -57,14 +62,25 @@ abstract class GraphQLGenerateSDLTask : SourceTask() {
5762
@OutputFile
5863
val schemaFile: RegularFileProperty = project.objects.fileProperty()
5964

60-
@Inject
61-
abstract fun getWorkerExecutor(): WorkerExecutor
65+
@get:Inject
66+
abstract val workerExecutor: WorkerExecutor
67+
68+
@get:Inject
69+
protected abstract val javaToolchainService: JavaToolchainService
70+
71+
@get:Nested
72+
abstract val launcher: Property<JavaLauncher>
6273

6374
init {
6475
group = "GraphQL"
6576
description = "Generate GraphQL schema in SDL format."
6677

6778
schemaFile.convention(project.layout.buildDirectory.file("schema.graphql"))
79+
80+
@Suppress("LeakingThis")
81+
project.extensions.getByType(JavaPluginExtension::class.java).toolchain
82+
.let(javaToolchainService::launcherFor)
83+
.let(launcher::convention)
6884
}
6985

7086
@TaskAction
@@ -80,7 +96,12 @@ abstract class GraphQLGenerateSDLTask : SourceTask() {
8096
throw RuntimeException("failed to generate target schema directory = $targetDirectory")
8197
}
8298

83-
val workQueue: WorkQueue = getWorkerExecutor().classLoaderIsolation { workerSpec: ClassLoaderWorkerSpec ->
99+
val workQueue: WorkQueue = workerExecutor.processIsolation { workerSpec: ProcessWorkerSpec ->
100+
workerSpec.forkOptions {
101+
it.setExecutable(launcher.get().executablePath.asFile)
102+
}
103+
logger.debug("worker executable: \n${workerSpec.forkOptions.executable}")
104+
84105
val workerClasspath = pluginClasspath.plus(projectClasspath).plus(source.files)
85106
workerSpec.classpath.from(workerClasspath)
86107
logger.debug("worker classpath: \n${workerSpec.classpath.files.joinToString("\n")}")

0 commit comments

Comments
 (0)