1

I have a build that generates Android artefacts (mainly an .aar) and bundles in dokka-generated docs (codebase is Kotlin+Java).

With some recent changes dokka started failing with this cryptic error:

> Task :mylib:dokka FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mylib:dokka'.
> com.intellij.psi.impl.source.PsiClassImpl cannot be cast to com.intellij.psi.PsiJavaFile

Any help would be appreciated. I currently cannot seem to trace the source of this.

d4vidi
  • 2,407
  • 26
  • 27

1 Answers1

0

I can't pin-point the root of the problem but I can say for sure that Dokka has some issues with annotation classes.

In my changes, I had initially introduced a new annotation class based on Android's @IntDef inside an abstract class (alongside associated helper methods), written in Java.

These 2 steps seemed to have helped:

  1. Switching to Kotlin for the annotation class' implementation, then defining the annotation class at a file's root scope (rather than as an inner item of a class).

  2. Suppressing the annotation's package in Dokka's config, i.e. -

dokka {
  ...

  packageOptions {
    prefix = "com.mylib.myannotation"
    suppress = true
  }
}

The end result is that the documentation cannot reference the annotated class (that's no surprise, as it was suppressed), but the javadoc generation fully succeeded.

d4vidi
  • 2,407
  • 26
  • 27
  • In my case, I only had to take step #1 to resolve the ClassCastException. I did not have to suppress the new package where the annotation exists. In fact, in most cases all I did was move the annotation from an inner class to a top-level class in the same package, and it resolved the issue for me. – Joe Jul 26 '19 at 17:15
  • Interesting! I don't recall now what the error was before applying step #2, but if I recall correctly it failed to parse. – d4vidi Jul 28 '19 at 07:14