I have an Android app that is built with Maven. Using the buildnumber-maven-plugin module and maven-resources-plugin module, I embed the maven project version and the git commit hash code in AndroidManifest. The create buildnumber-maven-plugin target runs in the validate phase, and the resources target to run the maven-resources-plugin runs in the initialize phase.
When building through the command line (with mvn install ), everything works fine, and the build number is displayed correctly in the prepared manifest.
However, when creating via Android Studio or IntelliJ, the git has not hash code is missing (the Maven property is not replaced by the actual value) in the manifest, but the project version is maven.
Why?
FYI: Android Studio runs the phase processes of the Maven process before Make, so it should work.
On the command line, I am using Maven 3.0.3, so this may be a version issue (although I cannot find out which version IntelliJ is using).
Here is my POM assembly element:
<build> <sourceDirectory>src</sourceDirectory> <testSourceDirectory>test</testSourceDirectory> <resources> <resource> <directory>${project.basedir}</directory> <filtering>true</filtering> <targetPath>${project.build.directory}/filtered-manifest</targetPath> <includes> <include>AndroidManifest.xml</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>${maven.buildnumber.version}</version> <configuration> <doCheck>false</doCheck> <doUpdate>false</doUpdate> <shortRevisionLength>6</shortRevisionLength> <revisionOnScmFailure>000000</revisionOnScmFailure> </configuration> <executions> <execution> <phase>validate</phase> <goals> <goal>create</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>${maven.resources.version}</version> <executions> <execution> <phase>initialize</phase> <goals> <goal>resources</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <extensions>true</extensions> <configuration> <androidManifestFile>${project.build.directory}/filtered-manifest/AndroidManifest.xml</androidManifestFile> </configuration> </plugin> </plugins> </build>
And the name versionName in my AndroidManifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.somecompany" android:versionCode="1" android:versionName="${project.version}-${buildNumber}" >
From the command line, both $ {project.version} and $ {buildNumber} are populated correctly with their values, from IntelliJ $ {buildNumber} is not present and just displays as "$ {buildNumber}": this indicates (since I set revisionOnScmFailure ) that the plugin does not start at all.
I tried to change the create target to run in the initialize phase (in case IntelliJ skipped validate ), but that didn't make any difference.