Posted by: Marek | March 21, 2009

Compiling production and test code with different settings

Even tough CLDC and MIDP applications need to be compiled to Java 1.3, it is often convenient to compile the test code with different settings so that Java features like annotations or generics can be used in test cases. The following example shows how to achieve that:

<build>

<plugins>

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<executions>

<execution>

<id>compile</id>

<phase>compile</phase>

<goals>

<goal>compile</goal>

</goals>

<configuration>

<source>1.3</source>

<target>1.3</target>

<compilerArguments>

<bootclasspath>

${settings.localRepository}/org/microemu/cldcapi11/${j2me.version}/cldcapi11-${j2me.version}.jar${path.separator}${settings.localRepository}/org/microemu/midpapi20/${j2me.version}/midpapi20-${j2me.version}.jar

</bootclasspath>

</compilerArguments>

</configuration>

</execution>

<execution>

<id>test-compile</id>

<phase>process-test-sources</phase>

<goals>

<goal>testCompile</goal>

</goals>

<configuration>

<source>1.6</source>

<target>1.6</target>

</configuration>

</execution>

</executions>

</plugin>

</plugins>

</build>


Note that the testCompile goal needs to be bound to the process-test-sources rather than test-compile, otherwise it will not work correctly (tested with Maven 2.0.9). This seems to be a bug in Maven.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: