Skip to content

Commit 5a9bf69

Browse files
committed
Configure the Dokka Gradle plugin and its tasks with code copied and 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.
1 parent 8a07be7 commit 5a9bf69

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
tasks.wrapper {
22
distributionType = Wrapper.DistributionType.ALL
33
}
4+
5+
plugins {
6+
id("org.jetbrains.dokka")
7+
}
8+
9+
dependencies {
10+
subprojects.filter { it.name.startsWith(project.name) }.forEach {
11+
dokka(it)
12+
}
13+
}

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ dependencies {
1818
implementation("com.huanshankeji.team:gradle-plugins:0.6.0") // don't use a snapshot version in a main branch
1919
implementation("com.android.tools.build:gradle:8.5.2")
2020
implementation("com.huanshankeji:common-gradle-dependencies:0.8.0-20241016") // don't use a snapshot version in a main branch
21+
implementation("org.jetbrains.dokka:dokka-gradle-plugin:2.0.0-Beta")
2122
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
id("org.jetbrains.dokka")
3+
}
4+
5+
dokka {
6+
dokkaSourceSets.all {
7+
sourceLink {
8+
remoteUrl("https://github.com/huanshankeji/compose-multiplatform-material/tree/v${version}/${project.name}")
9+
remoteLineSuffix.set("#L")
10+
}
11+
}
12+
13+
// https://github.com/Kotlin/dokka/issues/3885#issuecomment-2449645480
14+
dokkaGeneratorIsolation = ClassLoaderIsolation()
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
22
id("lib-conventions-without-publishing")
3+
id("dokka-convention")
34
id("com.huanshankeji.kotlin-multiplatform-sonatype-ossrh-publish-conventions")
45
}

gradle.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# For Wasm
2-
# More memory is needed now to compile the Wasm target in Gradle
3-
org.gradle.jvmargs=-Xmx2G
2+
# 2 GB for compiling the Wasm target and 16 GB for Dokka
3+
org.gradle.jvmargs=-Xmx32G
44
# For the `androidxCommon` custom source sets
55
#kotlin.mpp.applyDefaultHierarchyTemplate=false
66
# For Android
77
android.useAndroidX=true
8+
# for Dokka
9+
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled

0 commit comments

Comments
 (0)