How can I run maven compilation twice using the exec plugin between them?

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> 
+4
source share
1 answer

Allows compilation in source sources. Simply configure the maven-compiler-plugin to execute on this particular phase of the life cycle and place the generated code (compiled code) somewhere else than the default. Secondly, let your execution be performed in the after phase (source processes) and, finally, let the rest do as usual. The result of this is that you have to bind the maven-compiler plugin to the source generation phase, the exec plugin to the process lifecycle phase.

+5
source

Source: https://habr.com/ru/post/1435903/


All Articles