You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -157,6 +157,8 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
Copy file name to clipboardExpand all lines: modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt
+22Lines changed: 22 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -409,6 +409,28 @@ open class OpenApiGeneratorGenerateExtension(private val project: Project) {
409
409
*/
410
410
val dryRun = project.objects.property<Boolean>()
411
411
412
+
/**
413
+
* Controls how the code generation worker is isolated from the Gradle daemon.
414
+
*
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
420
+
* when the worker exits. Gradle reuses the worker process across tasks that share the same
421
+
* classpath, so the JVM startup cost is typically paid only once per parallel slot.
422
+
* Best for projects with many generation tasks.
423
+
*/
424
+
val workerIsolation = project.objects.property<String>()
425
+
426
+
/**
427
+
* Maximum heap size for the worker process when [workerIsolation] is "process" (e.g. "512m", "1g").
428
+
* Has no effect when [workerIsolation] is "classloader".
429
+
* When not set, the JVM uses ergonomic defaults (typically based on available system memory).
430
+
* Only set this if you hit OutOfMemoryError during generation of unusually large specs.
431
+
*/
432
+
val maxWorkerHeapSize = project.objects.property<String>()
Copy file name to clipboardExpand all lines: modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt
+58-2Lines changed: 58 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -282,6 +282,33 @@ abstract class GenerateTask : DefaultTask() {
282
282
@get:Inject
283
283
abstractval layout:ProjectLayout
284
284
285
+
/**
286
+
* Controls how the code generation worker is isolated from the Gradle daemon.
287
+
*
288
+
* - "process" (default): runs in a separate JVM process. Metaspace is fully isolated from the
289
+
* daemon and freed after the process exits. Gradle reuses the worker process across tasks that
290
+
* share the same classpath, so the JVM startup cost is paid at most once per parallel slot —
291
+
* not once per task. Best for projects with many generation tasks.
292
+
*
293
+
* - "classloader": runs inside the Gradle daemon JVM using a separate ClassLoader. No process
294
+
* startup overhead, but each task loads generator classes into the daemon's Metaspace. With
295
+
* many tasks this can exhaust Metaspace. Suitable for projects with very few tasks where the
296
+
* daemon memory budget is not a concern.
297
+
*/
298
+
@get:Optional
299
+
@get:Input
300
+
abstractval workerIsolation:Property<String>
301
+
302
+
/**
303
+
* Maximum heap size for the worker process when [workerIsolation] is "process" (e.g. "512m", "1g").
304
+
* Has no effect when [workerIsolation] is "classloader".
305
+
* When not set, the JVM uses ergonomic defaults (typically based on available system memory).
306
+
* Only set this if you hit OutOfMemoryError during generation of unusually large specs.
307
+
*/
308
+
@get:Optional
309
+
@get:Input
310
+
abstractval maxWorkerHeapSize:Property<String>
311
+
285
312
/**
286
313
* The verbosity of generation
287
314
*/
@@ -863,8 +890,37 @@ abstract class GenerateTask : DefaultTask() {
863
890
}
864
891
}
865
892
866
-
// Submit generation logic to the isolated Worker API Queue
867
-
val workQueue = workerExecutor.classLoaderIsolation()
893
+
// Submit generation work using the configured isolation mode.
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
897
+
// exits, and Gradle reuses the same worker daemon across tasks that share the same classpath,
898
+
// so startup cost is amortized — typically paid only once per parallel slot.
899
+
val isolation = workerIsolation.getOrElse("classloader").lowercase()
900
+
val workQueue =when (isolation) {
901
+
"process"-> {
902
+
val heapMsg = maxWorkerHeapSize.orNull?.let { " (maxHeapSize=$it)" } ?:""
0 commit comments