Guide to generating sources

Let's run though a short example. To generate sources you must first have a plugin that participates in the generate-sources phase like the ANTLR4 Maven Plugin. You configure its execution in the POM:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <version>4.5.3</version>
        <executions>
          <execution>
            <id>antlr</id>
            <goals>
              <goal>antlr4</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

When you type mvn compile, Maven walks through the lifecycle and eventually hits the generate-sources phase. It sees that a plugin is configured that wants to participate in that phase, and executes the ANTLR4 Maven Plugin with the given configuration. Later, during the compile phase, all the code generated from the grammar files is compiled without further configuration.