title: Generating ANTLR4 grammar files with package declaration in gradle
body: <p>I try to use the gradle antlr plugin, but run into several problems.</p>
  
  <p>I have a grammar file called <code>wls.g4</code>:</p>
  
  <pre><code>grammar WlsScript;
  
  @header {
     package hu.pmi.wls.antlr.ws;
  } 
  
  program
    : 'statementList'? EOF
    ;
  
  // Several more grammar and lexer rules
  </code></pre>
  
  <p>(<em>Note: I made the statementList to a keyword only to make a correct grammer without including the whole grammar. ;-)</em>)</p>
  
  <p>This file is located in /src/main/antlr (as the default source folder of the antlr production grammar files). </p>
  
  <p>Here is the snippet from <code>build.gradle</code>:</p>
  
  <pre><code>project('common') {
  
      apply plugin: 'antlr'
  
      dependencies {
         // Some dependencies
  
         antlr "org.antlr:antlr4:4.5"
      }
  } 
  </code></pre>
  
  <p>When I use the <code>generateGrammarSource</code> gradle task (comming from <code>antlr</code> plugin) to generate the source files it generates the files in <code>build/generated-src/antlr/main</code> folder which is the default. </p>
  
  <p>What goes wrong, that it doesn't create the folders of the java package (<code>hu/pmi/wls/antlr/ws</code> in our case) so the source will be incorrectly located in Eclipse.</p>
  
  <p><strong>My primary question is how could I force the task to generate source files in a package-structured way?</strong> In other words, how can I configure the gradle task to use the package declaration from grammar?</p>
  
  <p>Thanks!</p>