Outputting compilation errors to a file?

I want compilation errors to be outputted to a file such that vim can read it to populate the quickfix buffer.

I have tried doing

gradle compileJava > errors.err

But this doesn’t output the errors to the file:

$ cat errors.err
:compileJava FAILED
  BUILD FAILED
  Total time: 5.217 secs

Additionally I believe this method would write non-error lines to the file.

To summarize: I would like the compilation errors from compileJava to be outputted to a file. Is this possible, if so how?