Let's run though a short example to try and help. To generate sources you must first have a plugin that participates in the generate-sources phase like the ANTLR4 Maven Plugin.
So this is all fine and dandy, we have a plugin that wants to generate some sources from a Antlr4 grammar but how do we use it. You need to specify that you want to use it in your 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>
If you then type mvn compile Maven will walk through the lifecycle and will eventually hit the generate-sources phase and see you have a plugin configured that wants to participate in that phase and the ANTLR4 Maven Plugin is executed with your given configuration. Furthermore during the compile you can observe that all the generated code (from your grammar files) will automatically being compiled without supplemental configuration.