Debugging¶
One major downside to generating IR directly is that developers cannot step into generated source code with the debugger. This is an accepted trade-off with Metro (or any other compiler plugin).
Metro does offer a debug option in its plugin options/Gradle extension that will print verbose Kotlin pseudocode for all generated IR classes. This can be further tuned to print just certain classes.
metro {
debug.set(true)
}
In the future, we could possibly explore including information in IR to synthesize call stack information similar to coroutines, but will save that for if/when it’s asked for.
Reports¶
Similar to Compose, Metro supports a reportsDestination property in its Gradle DSL and can output various graph reports to this destination if specified. This is very much a WIP, feedback is welcome!
Warning
You should not leave this enabled by default as it can be quite verbose and potentially expensive. This property also does not participate in task inputs, so you may need to recompile with --rerun to force recompilation after adding this flag.
metro {
reportsDestination.set(layout.buildDirectory.dir("metro/reports"))
}
Warning
The Kotlin Gradle Plugin does not include file inputs like reportsDestination as build inputs, so you may need to compile with --rerun to force recompilation after adding this flag.
Graph Analysis & Visualization¶
Metro provides Gradle tasks for generating interactive HTML visualizations of your dependency graphs. See Graph Analysis for full documentation on:
- Generating and viewing interactive graph visualizations
- Understanding node shapes, colors, and edge types
- Using filters and analysis tools
- Identifying potential issues in your dependency structure
Decompiled Bytecode¶
Compiled java class files of Metro-generated types are fairly friendly to the IntelliJ “decompile to Java” action. Simply open the class file in the IDE (usually seen as a Kotlin bytecode class) then run the “decompile to Java” action. For JVM projects they are under build/classes. For Android projects, it’s build/tmp/kotlin-classes.