Skip to content
Tony Robalik edited this page Apr 21, 2024 · 3 revisions

TypeNotPresentException: Type org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension in Kotlin jvm library

This error is due to the unavoidable fact that, if your build uses Kotlin in any of its subprojects, then this plugin’s classes must be loaded in the same classloader as the Kotlin Gradle Plugin. This is discussed in the Gradle community slack here. To understand what’s going on, consider the following:

root build.gradle
plugins {
  id("com.autonomousapps.dependency-analysis") version("<latest-version>")
}
library/build.gradle
plugins {
  id("org.jetbrains.kotlin.jvm") version("<latest-version>")
}

If you now try to invoke either ./gradlew buildHealth or ./gradlew library:projectHealth, the build will fail with a TypeNotPresentException. Fixing this is simple:

root build.gradle
plugins {
  id("com.autonomousapps.dependency-analysis") version("<latest-version>")
  id("org.jetbrains.kotlin.jvm") version("<latest-version>") apply false
}
library/build.gradle
plugins {
  id("org.jetbrains.kotlin.jvm") // version would be an error
}

The reason this solves the problem is that it loads both this plugin and the Kotlin Gradle Plugin in the same classloader. This limitation may one day go away, but you should not hold your breath.

The Daemon will expire after the build after running out of JVM Metaspace

The nature of the analysis performed by this plugin is such that builds tend to require more than the default amount of metaspace provided by the JVM. This is simply (probably?) unavoidable. Since Gradle 5, the default max metaspace provided by Gradle-managed JVMs has been 256 MiB. To increase the limit, use the -XX:MaxMetaspaceSize flag:

gradle.properties
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m

How to skip analyzing test sources and test dependencies?

For various reasons, you may want to skip analyzing test dependencies. For example, because it makes the analysis take longer and you’re not concerned about tests at the moment.

To skip test analysis, set the system property dependency.analysis.test.analysis=false. This can be done on an ad hoc basis with -Ddependency.analysis.test.analysis=false, per permanently by setting the following:

gradle.properties
systemProp.dependency.analysis.test.analysis=false