Profile Kotlin compilation with gradle

I am working on a Kotlin project that takes surprisingly long to compile and I would like to figure out what takes so long. The project has about 16500 lines of Kotlin code and takes about 2 minutes to compile on my laptop (Ryzen 7 4570U, 32GB Ram). I already identified a few possible culprits but have not seen dramatic improvements so far:

  • Reduce number of classes drastically (went from over 4000 (lots of inline lambdas) down to a few hundred)
  • Split up code into more but smaller files
  • Upgrade from kotlin version 1.3.72 to 1.4.21 (that actually made it a little slower)

The project adds extension functions and operator overloading to a Java image processing library that makes extensive use of recursive generics. I could imagine that those recursive generics pose a significant challenge to the compiler.

Is there an option to profile the time spent on individual files/classes/functions with the Kotlin compiler or, even better, gradle?

I found the --scan option just after creating this post, which does exactly what I need. :man_facepalming:
Well, hopefully this thread will be useful to others who are looking for a similar thing

edit: Actually, it does not give me per-file insights, unfortunately.