Grab compilation errors from java build

I have an existing plugin for Intellij and one feature request was to collect any compilation errors from builds done in the IDE ( in the console) . I was trying to avoid having the plugin start the build but that is an option incase that would give me access to better availability of compilation errors. My googling and research has not turned up anything so far.

i did find https://intellij-support.jetbrains.com/hc/en-us/community/posts/203361530-Read-text-from-Run-window but its not working for me.

Hello! You may use experimental API BuildViewManager::addListener:

project.getService(BuildViewManager.class).addListener((buildId, event) -> {
  if (event instanceof MessageEvent messageEvent && 
      messageEvent.getKind() == MessageEvent.Kind.ERROR) {
    System.out.println("Error: "+event.getMessage());
  }
}, someDisposable);