If I compile a kotlin file using the build in compilation task in IntelliJ, and that file produces a compilation error, the following will happen:
- The build output will include a clickable line of text. Clicking it navigates to the location.
/my/project/code.kt:79:119: Expecting an expression
- IntelliJ will jump to the location of the first error it sees automatically
- The run tool window of intelliJ will list all such errors to the left of the console
- We can cycle through those errors, jumping to each as we cycle, using IntelliJ keyboard shortcuts.
I am seeking to make my custom gradle task produce errors with the same rich IDE support. So far, I have not been successful.
First, I tried to use the Problems API. I didn’t see anywhere a specification of what phase the Problems API could be used in, but so far I have only been able to successfully use it from the configuration phase. Here, I needed to use it from the task execution phase so I tried to @Inject it, but got an error about the service not being available. So I am assuming it is currently only intended for the configuration phase.
Next, I tried to just print the location. I essentially just did this in my custom task action:
throw GradleException("${file.path}:${it.line}:${it.col}: ${it.message}")
This was partially successful. It produced clickable output, and the IDE partially recognized that output as an error. Clicking the output in the console successfully navigated to the source location. However, some of the rich features are still missing:
- The IDE did not automatically navigate to the first instance of my failure
- The list of errors in the run tool window didn’t properly register my error as navigable apparently, because double clicking the error in the list (not in the console) doesn’t navigate to it. Also, the keyboard shortcuts to cycle through errors don’t work.
I suspect that Gradle+IntelliJ are using some special API to register navigable errors thrown at task execution time. Its also possible that IntelliJ could be looking for a specific format of error output in order to get rich support. Does anyone know?