ktlint-gradle: Memory leak in ktlintFormat task

Probably related with #447

I’m running git rebase -i develop --exec "./gradlew ktlintFormat" on a branch with 40 commits and I’m getting this error on my local machine (macOS):

> A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
   > Java heap space

It seems like a leak to me. The first 5 coomits ok, then the next failed. I reran the task manually on that commit and it worked. But then the 8th commit failed. and the pattern continued until the commit 15th. I can’t run the task any more. It fails every single time with the error I pasted above. As soon as I killed the daemon ./gradlew --stop it worked.

I’m using v10.1.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 18 (1 by maintainers)

Most upvoted comments

Yes, for some unknown reason (Kotlin update) Ktlint 0.41.0 uses more memory then before…

Okay, so I’ve been running with version 0.43.0 since this was last updated, and I just now started seeing this issue again.

> Task :app:runKtlintFormatOverMainSourceSet FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:runKtlintFormatOverMainSourceSet'.
> A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
   > Java heap space

Can also confirm: Explicitly setting the ktlint-version to 0.43.0 seems to have solved the problem for me as well.

ktlint {
  version = "0.43.0"
}

I have run into the same issue as well. Even changing the following to 4096m is still failing. I had to remove my ktlint pre-push hook to be able to push to my project.

tasks.withType<org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask> {
    workerMaxHeapSize.set("512m")
}

I can’t reproduce this issue anymore. @gabrielittner if you can confirm it too I can close the issue. @breispeloton thanks for the heads up!

@breispeloton Thanks! I’ve updated our plugin and hopefully it will be resolved.

Just an FYI for anyone seeing this that this may have been fixed in ktlint 0.43.0. See https://github.com/pinterest/ktlint/issues/1216 and the linked kotlinter-gradle issue.

I know it doesn’t solve the issue, but you can still increase the heap size as described in the README since the default heap is 256 mb.

tasks.withType<org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask> {
    workerMaxHeapSize.set("512m")
}