I am trying to fix a compiler plugin for Gradle. Gradle generates error messages of the type:

:compileJava/file/path/Main.java:52: error: cannot find symbol
    public static ABC abc;
  symbol:   class ABC
  location: class Main
/file/path/Main2.java:291: error: incompatible types: com.whatever.N cannot be converted to com.another.N
... and so on

All error messages except for the first one are properly parsed with this error format string

CompilerSet errorformat=
  \%E%f:%l:\ error:\ %m

The problem is that Gradle prepends a target name (in this case :compileJava) to the first error message. My question is: how do I specify that :compileJava (and maybe some other :compileTarget) strings can be optionally included at the beginning of the error message?

If I were to write a regexp in a more common format, this would look similar to:



1 Answer 1


I suggest doing it like this:

let &errorformat =
    \ '%E%\m:%\%%(compileJava%\|compileTarget%\)%f:%l: error: %m,' .
    \ '%E%f:%l: error: %m,' .
    \ '%Z%p^,' .
    \ '%-G%.%#'


cgetexpr [':compileJava/file/path/Main.java:52: error: cannot find symbol',
    \ '    public static ABC abc;',
    \ '                  ^',
    \ '  symbol:   class ABC',
    \ '  location: class Main',
    \ '/file/path/Main2.java:291: error: incompatible types: com.whatever.N cannot be converted to com.another.N' ]
echomsg string(getqflist())


[{'lnum': 52, 'bufnr': 3, 'col': 19, 'valid': 1, 'vcol': 1, 'nr': -1, 'type': 'E', 'pattern': '', 'text': 'cannot find symbol'},
 {'lnum': 291, 'bufnr': 4, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': 'E', 'pattern': '', 'text': 'incompatible types: com.whatever.N cannot be converted to com.another.N'}]
  • Wow! It worked! Thanks so much! If possible, can you please explain the solution a bit more? As i understand, dots (.) are used for string concatenation, right? And instead of escaping all spaces etc., errorformat string is surrounded by quotes. But what does %\%% sequence mean? And what is the difference between let &errorformat and CompilerSet errorformat? (the latter does not work with the efm string specified above).
    – vitvly
    Jul 28, 2015 at 20:35
  • 1
    @siphiuel If you read the docs, you will find that the errorformats are tried consecutively until one matches. The first entries have highest priority. Thus the solution by @lcd047 consists of 4 entries, where the first one matches errors that contains the compileJava or compileTarget lines. The second matches the other errors, the third defines a "pointer line" and the end of en error message, and the final entry says to ignore every remaining lines. Jul 28, 2015 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.