Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.45k stars 410 forks source link

Gradle process isolation not setting JVM memory args correctly #3933

Open ecopoesis opened 2 days ago

ecopoesis commented 2 days ago

Describe the bug Using 2.0.0-Beta on a large multi-module project, I get OOMs when running ./gradlew dokkaGenerate. To attempt to fix this, I've tried adding the following section to my top level build.gradle.kts:

    dokkaGeneratorIsolation = ProcessIsolation {
        minHeapSize = "4g"
        maxHeapSize = "8g"
    }

I've also tried with explicit sets:

    dokkaGeneratorIsolation.set(ProcessIsolation {
        minHeapSize.set("4g")
        maxHeapSize.set("8g")
    })

I'm still getting OOMs because Gradle workers are launched with -Xmx512m. From ps:

502 60919 60882   0  4:03PM ??         0:49.40 /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home/bin/java -XX:+HeapDumpOnOutOfMemoryError -XX:+AlwaysPreTouch @/Users/mroberts/.gradle/.tmp/gradle-worker-classpath5758653660898353623txt -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Worker Daemon 2'

I usually see 10 versions of these. Gradle is running with 12 parallel tasks.

Expected behaviour Workers should launch with Xms4g -Xmx8g

To Reproduce

Use the above dokka config in a Gradle multimodule project.

Dokka configuration Configuration of dokka used to reproduce the bug

Submodules are getting the Dokka plugin via a convention plugin:

plugins {
    kotlin("jvm")
    kotlin("plugin.assignment")
    kotlin("plugin.serialization")
    id("io.gitlab.arturbosch.detekt")
    id("org.jetbrains.dokka")
}

Dokka related config in root build.gradle.kts:

dependencies {
    project.allprojects.filterNot { proj -> proj.name == rootProject.name }.forEach { proj -> dokka(proj) }
}

dokka {
    moduleName.set(project.name)

    dokkaGeneratorIsolation = ProcessIsolation {
        minHeapSize = "4g"
        maxHeapSize = "8g"
    }

    dokkaSourceSets {
        configureEach {
            jdkVersion.set(JavaVersion.VERSION_21.majorVersion.toInt())
            languageVersion.set("1.9")
        }
    }

    dokkaPublications.html {
        outputDirectory.set(File("$projectDir/sphinx/source/_static/dokka"))
    }
}

gradle.properties:

org.gradle.parallel=true
org.gradle.caching=true
org.gradle.project.enablePTS=true
org.gradle.configuration-cache=true
org.gradle.configureondemand=false
org.gradle.daemon.idletimeout=60
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
org.gradle.jvmargs=-Dfile.encoding=UTF-8 \
                   -Xmx4096M \
                   -XX:ThreadStackSize=4096 \
                   -XX:CompilerThreadStackSize=4096 \
                   -Dlog4j2.formatMsgNoLookups=true \
                   --add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
                   --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
                   --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
                   --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
                   --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED  \
                   --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
                   --add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
                   --add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
                   --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
                   --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
                   --add-opens java.base/java.time=ALL-UNNAMED

Installation

adam-enko commented 3 hours ago

Hi, thanks for the report.

Just to double check, are the memory settings only configured in the root build.gradle.kts, or for all projects in the Dokka convention plugin? Dokka config defined in the root build script isn't shared with subprojects, and must be configured per-project with the convention plugin.