Search code examples
javaintellij-ideaintellij-plugin

Failing compilation based on custom errors from a custom plugin Intellij


I am currently trying to develop a custom plugin for Intellij Idea using Gradle that identifies more errors in Java code (things like logic errors that the compiler doesn't highlight). I know that a warning would technically be sufficient, but I need these custom errors to prevent the project from compiling. I found a way to highlight the errors using an Annotator, but I can't find a way to prevent the project from compiling and running when these errors are present. I haven't been able to find any documentation about failing compilation based on custom errors for Intellij plugins. Does anyone know of a way to prevent compilation from a custom Intellij plugin given custom errors in the file/project?

I've tried to use a custom CompileTask, AnnotationProcessor, and ExecutionListener. The CompileTask is the only one that manages to fail the compilation, but I can't get it to fail only when the custom errors are present. I have been searching for solutions for about a week and haven't managed to find something that works. Any help at all is greatly appreciated!!


Solution

  • I reached out to the Intellij Plugin support and asked them this question and they gave me an answer that worked! I used a CompileTask to prevent the project from compiling given my custom errors. Here is the link! https://intellij-support.jetbrains.com/hc/en-us/community/posts/19391360731410-Creating-a-Compiler-Error-from-a-plugin