An sbt plugin to fix java.lang.OutOfMemoryError: Metaspace/PermGen
errors during interactive sbt usage
- Hooks into
sbt test
in jvm projects, andsbt run
in PlayFramework projects - Automatically fixes known leaks using mjiderhamn/classloader-leak-prevention
- Detects and warns if classloader leaks if still occur, and optionally generates a heap dump
Add the following line to your project/plugins.sbt
:
addSbtPlugin("com.github.dwickern" % "sbt-classloader-leak-prevention" % "0.4")
Key | Type | Default | Description |
---|---|---|---|
ClassLoaderLeakPreventor.enableLeakPrevention | Boolean | true | Whether to use automatic ClassLoader leak prevention |
ClassLoaderLeakPreventor.enableLeakDetection | Boolean | true | Whether to check for a leaking ClassLoader |
ClassLoaderLeakPreventor.leakDetectionAttempts | Int | 5 | Maximum number of leak detection attempts |
ClassLoaderLeakPreventor.leakDetectionInterval | FiniteDuration | 2.seconds | How long to wait between leak detection attempts |
ClassLoaderLeakPreventor.enableLeakDetectionHeapDump | Boolean | false | Whether to create a heap dump when a ClassLoader leak is detected |
ClassLoaderLeakPreventor.stopThreads | Boolean | true | Whether to force threads to stop |
ClassLoaderLeakPreventor.stopTimerThreads | Boolean | true | Whether to force timer threads to stop |
ClassLoaderLeakPreventor.executeShutdownHooks | Boolean | true | Whether to execute shutdown hooks |
ClassLoaderLeakPreventor.startOracleTimeoutThread | Boolean | true | Whether to force the Oracle JDBC timer thread to start |
ClassLoaderLeakPreventor.threadWait | FiniteDuration | 5.seconds | How long to wait for threads to finish before stopping them |
ClassLoaderLeakPreventor.shutdownHookWait | FiniteDuration | 10.seconds | How long to wait for shutdown hooks to finish before stopping them |
To run tests:
sbt scripted
To publish locally:
sbt publishLocal
To publish to maven central (requires authorization):
sbt release