I have a simple G code generator that reads interface A from my project and generates a new interface B from it. So I need to do this:
- Compile A
- Run g
- Compilation B
Steps 1 and 3 are handled by the maven-compiler plugin, and for step 2 I use the maven-exec-plugin. Currently steps 1 and 2 are working fine, but I cannot figure out how to run the compiler plugin again in order to compile the newly generated version of B.
Is this possible with maven, or is there a different approach to solving my problem?
Decision:
Based on khmarbaise's answer, I added this to my pom.xml so that the first compilation run is performed at the source generation stage and code generation at the process source phase, which makes the generated class available at the compilation stage:
<build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <executions> <execution> <id>pre-compile</id> <phase>generate-sources</phase> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <phase>process-sources</phase> <goals> <goal>java</goal> </goals> <configuration> <mainClass>com.example.MyCodeGenerator</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build>
source share