Reputation: 451
In my Maven 1 Java project I use sort of external data to create classes for compilation, thus I have to divide compilation into two steps: compile program, analyze data and create classes, compile those classes.
How may I describe such scenario in my pom.xml
file?
Upvotes: 1
Views: 326
Reputation: 27812
Is Maven 1 an hard requirement? In Maven 3, you could apply the following configuration to your POM:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>retrieve-config</id>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- replace by your generation step -->
<executable>echo</executable>
<arguments>
<argument>public</argument>
<argument>class</argument>
<argument>Main{}</argument>
<argument>></argument>
<argument>Main.java</argument>
</arguments>
<workingDirectory>${basedir}/src/main2/</workingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>second-compilation-add-sources</id>
<phase>process-classes</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main2</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>second-compilation-compile</id>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<exclude>src/main/java/**/*.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
In the configuration above three plugins are:
I just tried it and it works fine on my machine (Windows machine).
Please note that the configuration above is just an example, I dynamically wrote in a text file a simple Java class via the echo command, then added its folder (the src/main2
, which I previously created) to the compilation path and then compiled it. All as part of the process-classes
phase, which happens right after the compile
phase.
Using this approach, you can also test the whole code (generated and not) as part of the standard test
phase.
Upvotes: 1