Skip to content
Tony Robalik edited this page Oct 9, 2021 · 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.

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
Clone this wiki locally