Skip to content

Commit

Permalink
Configure the Dokka Gradle plugin and its tasks with code copied and …
Browse files Browse the repository at this point in the history
…adapted from "gradle-common", and resolve heap memory issues

A source commit: huanshankeji/gradle-common@c1c69c3

`java.lang.OutOfMemoryError: Java heap space` occurs when running the `dokkaGenerate` Gradle task without further configuration and is resolved with the approach from Kotlin/dokka#3885 (comment). The solution code `dokkaGeneratorIsolation = ClassLoaderIsolation()` has to be added to the subproject build scripts (the convention plugin) to work.

Moreover, this happens when the heap space is not enough:

```text
The Daemon will expire immediately since the JVM garbage collector is thrashing
The project memory settings are likely not configured or are configured to an insufficient value.
The memory settings for this project must be adjusted to avoid this failure.
These settings can be adjusted by setting 'org.gradle.jvmargs' in 'gradle.properties'.
The currently configured max heap space is '2 GiB' and the configured max metaspace is 'unknown'.
```

Therefore, `Xmx` in `org.gradle.jvmargs` is increased all the way to 32 GB. 4 GB and 8 GB still cause GC thrashing, and 16 GB is enough but the task takes more time compared to 32 GB with swap. The actual max memory usage is about 30 GB with the 32 GB max heap size. This seems to be caused by parallelism so to reduce the max memory usage, the `--max-workers` Gradle argument can be used and is tested to work. `--no-parallel` doesn't make a difference as tested, however.

Eventually, after the 2 issues above are fixed, the task still fails because of Kotlin/dokka#3900.
  • Loading branch information
ShreckYe committed Nov 6, 2024
1 parent 8a07be7 commit 5a9bf69
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}

plugins {
id("org.jetbrains.dokka")
}

dependencies {
subprojects.filter { it.name.startsWith(project.name) }.forEach {
dokka(it)
}
}
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ dependencies {
implementation("com.huanshankeji.team:gradle-plugins:0.6.0") // don't use a snapshot version in a main branch
implementation("com.android.tools.build:gradle:8.5.2")
implementation("com.huanshankeji:common-gradle-dependencies:0.8.0-20241016") // don't use a snapshot version in a main branch
implementation("org.jetbrains.dokka:dokka-gradle-plugin:2.0.0-Beta")
}
15 changes: 15 additions & 0 deletions buildSrc/src/main/kotlin/dokka-convention.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id("org.jetbrains.dokka")
}

dokka {
dokkaSourceSets.all {
sourceLink {
remoteUrl("https://github.com/huanshankeji/compose-multiplatform-material/tree/v${version}/${project.name}")
remoteLineSuffix.set("#L")
}
}

// https://github.com/Kotlin/dokka/issues/3885#issuecomment-2449645480
dokkaGeneratorIsolation = ClassLoaderIsolation()
}
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/lib-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id("lib-conventions-without-publishing")
id("dokka-convention")
id("com.huanshankeji.kotlin-multiplatform-sonatype-ossrh-publish-conventions")
}
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# For Wasm
# More memory is needed now to compile the Wasm target in Gradle
org.gradle.jvmargs=-Xmx2G
# 2 GB for compiling the Wasm target and 16 GB for Dokka
org.gradle.jvmargs=-Xmx32G
# For the `androidxCommon` custom source sets
#kotlin.mpp.applyDefaultHierarchyTemplate=false
# For Android
android.useAndroidX=true
# for Dokka
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled

0 comments on commit 5a9bf69

Please sign in to comment.