I have a Maven project within which I need execute two code generation steps. One generates some Java types, then the second depends on those Java types to generate some more code. Is there a way to have both of these steps happening during my build?
At the moment my steps are:
generate-sources
)compile
)However my problem is that anything generated by the second code generation plugin will not be compiled (because the compile phase has finished). If I attach the second code generation plugin to an earlier phase, it fails because it needs the classes from the first code generation plugin to be present on the classpath.
I know I could split this into two modules with one dependent on the other, but I was wondering if this could be achieved in one pom. It seems like a need a way to invoke compile again after the normal compile phase is complete.
Any ideas?
The compiler plugin is used to compile the source code of a Maven project. This plugin has two goals, which are already bound to specific phases of the default lifecycle: compile – compile main source files. testCompile – compile test source files.
pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.
Plugins are the central feature of Maven that allow for the reuse of common build logic across multiple projects.
Given the lifecycle phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the integration tests, install the verified ...
You can always configure two executions of the compiler plugin, both tied to the compile phase. In one you include the extra stuff:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>one</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration></configuration>
</execution>
<execution>
<id>two</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument>
</configuration>
</execution>
</executions>
<plugin>
You may try as well <includes><include>path/</include></includes>
According the official documentation:
When multiple executions are given that match a particular phase, they are executed in the order specified in the POM, with inherited executions running first.
But I quite not get what you exactly want. http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With