title: Groovy Syntax Checking in Java
body: <p>I'm implementing a Web-based Groovy code editor and need to check the code for syntax errors. The Java implementation below works OK but the resulting message contains some undesired elements (in bold). I'm looking for a way to list warnings and errors individually. 
  I'm using this maven dependency: <a href="http://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all/2.1.1" rel="nofollow">groovy-all 2.1.1</a></p>
  
  <pre><code>try {
      new GroovyShell().parse(groovyCode);            
  } catch(CompilationFailedException cfe) {
      System.out.println(cfe.getMessage());
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>startup failed:
  
  Script1.groovy: 1: unexpected token: n @ line 1, column 19.
  
  def factorial(n)  n == 1 ? 1 : n * factorial(n - 1) }
                           ^
  
  1 error
  </code></pre>