Skip to content

Commit e21f51f

Browse files
committed
implement feedback from CR
1 parent ab16391 commit e21f51f

3 files changed

Lines changed: 26 additions & 24 deletions

File tree

modules/openapi-generator-gradle-plugin/README.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,16 @@ file states is output.
446446
|`process`
447447
a|Controls how the code-generation work action is isolated from the Gradle daemon.
448448

449-
`process` (default):: Runs generation in a separate forked JVM. Generator classes are fully unloaded when the worker
449+
`classloader` (default):: Runs generation inside the Gradle daemon JVM using a separate `ClassLoader`. Avoids the per-task JVM
450+
startup overhead, but generator classes accumulate in the daemon's Metaspace across tasks and builds. Suitable for
451+
single-module projects or local developer loops where Metaspace pressure is not a concern.
452+
453+
`process`:: Runs generation in a separate forked JVM. Generator classes are fully unloaded when the worker
450454
exits, preventing Metaspace accumulation in the Gradle daemon. A small per-task JVM startup cost is incurred (~1–2 s
451455
amortized across parallel builds). Recommended for CI/CD and multi-project builds to avoid the
452456
https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory[metaspace exhaustion
453457
warning].
454458

455-
`classloader`:: Runs generation inside the Gradle daemon JVM using a separate `ClassLoader`. Avoids the per-task JVM
456-
startup overhead, but generator classes accumulate in the daemon's Metaspace across tasks and builds. Suitable for
457-
single-module projects or local developer loops where Metaspace pressure is not a concern.
458-
459459
|maxWorkerHeapSize
460460
|String / Provider<String>
461461
|Gradle default (~512 MiB)

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,14 @@ open class OpenApiGeneratorGenerateExtension(private val project: Project) {
412412
/**
413413
* Controls how the code generation worker is isolated from the Gradle daemon.
414414
*
415-
* - "process" (default): runs in a separate JVM. Metaspace is isolated from the daemon and freed
415+
* - "classloader" (default): runs inside the Gradle daemon JVM with a separate ClassLoader. No process
416+
* startup overhead, but generator classes accumulate in daemon Metaspace. Suitable for projects
417+
* with very few generation tasks.
418+
*
419+
* - "process": runs in a separate JVM. Metaspace is isolated from the daemon and freed
416420
* when the worker exits. Gradle reuses the worker process across tasks that share the same
417421
* classpath, so the JVM startup cost is typically paid only once per parallel slot.
418422
* Best for projects with many generation tasks.
419-
*
420-
* - "classloader": runs inside the Gradle daemon JVM with a separate ClassLoader. No process
421-
* startup overhead, but generator classes accumulate in daemon Metaspace. Suitable for projects
422-
* with very few generation tasks.
423423
*/
424424
val workerIsolation = project.objects.property<String>()
425425

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -891,23 +891,14 @@ abstract class GenerateTask : DefaultTask() {
891891
}
892892

893893
// Submit generation work using the configured isolation mode.
894-
// "process" (default): worker runs in a separate JVM; Metaspace is freed after each worker daemon
894+
// "classloader" (default): worker runs inside the Gradle daemon JVM with a separate ClassLoader; no startup
895+
// overhead but generator classes accumulate in daemon Metaspace across all tasks.
896+
// "process": worker runs in a separate JVM; Metaspace is freed after each worker daemon
895897
// exits, and Gradle reuses the same worker daemon across tasks that share the same classpath,
896898
// so startup cost is amortized — typically paid only once per parallel slot.
897-
// "classloader": worker runs inside the Gradle daemon JVM with a separate ClassLoader; no startup
898-
// overhead but generator classes accumulate in daemon Metaspace across all tasks.
899-
val isolation = workerIsolation.getOrElse("process").lowercase()
899+
val isolation = workerIsolation.getOrElse("classloader").lowercase()
900900
val workQueue = when (isolation) {
901-
"classloader" -> {
902-
logger.lifecycle(
903-
"[openApiGenerate] Worker isolation: classloader " +
904-
"(fast startup, but generator classes accumulate in Gradle daemon Metaspace - " +
905-
"consider workerIsolation = \"process\" if you hit metaspace pressure)"
906-
)
907-
workerExecutor.classLoaderIsolation()
908-
}
909-
910-
else -> {
901+
"process" -> {
911902
val heapMsg = maxWorkerHeapSize.orNull?.let { " (maxHeapSize=$it)" } ?: ""
912903
logger.lifecycle(
913904
"[openApiGenerate] Worker isolation: process$heapMsg " +
@@ -918,6 +909,17 @@ abstract class GenerateTask : DefaultTask() {
918909
maxWorkerHeapSize.orNull?.let { forkOptions.maxHeapSize = it }
919910
}
920911
}
912+
913+
"classloader" -> {
914+
logger.lifecycle(
915+
"[openApiGenerate] Worker isolation: classloader " +
916+
"(fast startup, but generator classes accumulate in Gradle daemon Metaspace - " +
917+
"consider workerIsolation = \"process\" if you hit metaspace pressure)"
918+
)
919+
workerExecutor.classLoaderIsolation()
920+
}
921+
922+
else -> throw GradleException("Invalid workerIsolation mode: $isolation. Supported values are 'process' and 'classloader'.")
921923
}
922924

923925
workQueue.submit(OpenApiWorkAction::class.java, object : Action<OpenApiWorkParameters> {

0 commit comments

Comments
 (0)