The last post explored how to enable Maven builds in a standard Android Eclipse project. This post will show how to enable the test project to be built with Maven.
It will be a bit simpler to enable Maven builds in the test project since we will not need to do any of the prep work. The only thing required is to create a pom file for the test project:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany</groupId>
<artifactId>your-test-artifact-id</artifactId>
<packaging>apk</packaging>
<version>0.0.1</version>
<name>Your Test Android project Maven Enabled</name>
<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.yourcompany</groupId>
<artifactId>your-artifact-id</artifactId>
<packaging>apk</packaging>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.yourcompany</groupId>
<artifactId>your-artifact-id</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId>
<configuration>
<sdk>
<path>${env.ANDROID_HOME}</path>
<platform>1.6</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project> |
This pom is similar to the pom in the main project but has two more dependencies. They are both pointing to the main project, one to the apk and one to the jar file. The dependency to the jar file is to enable the compiler to find your java classes from the main project. The dependency to the apk is to enable the android maven plugin to find the apk that it will run the tests against on the device or emulator when executing.
The android maven plugin can now run the tests using instrumentation, just like Eclipse does, as long as an emulator or Android device is connected. It uses the same underlying tools.
In order to execute the test the main project needs to be built and installed into the local Maven repository. This is done with the mvn install command in the main projects root folder. When the main project have been installed the same command, mvn install, will build and execute the tests when executed from within the test projects root.
Next post will explain how to create a project hierarchy that makes it possible to build and test the two projects with one command.
