Why is my pom not running correctly when using Android Studio / IntelliJ?

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.

+7
source share
1 answer

IntelliJ has its own internal build system, like any other IDE, and can create projects without the help of external tools. Intellij also integrates with Maven, interpreting pom.xml from your project and implementing it to create based on the configuration you defined. This works very well with most compilation tasks, but starts to crash when you introduce more complex plugins like buildnumber-maven-plugin. Unfortunately, IntelliJ has no internal equivalent to handle this plugin, so the $ {buildNumber} property is never populated.

Possible workarounds:

  • Do not create your project using the built-in IntelliJ system, use the "Maven Projects" panel, which you can show by going to "View"> "Toolbar"> "Maven Projects". This gives you access to all standard Maven phases and other functions.

  • In your IntelliJ startup configuration, add an environment variable called "buildNumber" and give it whatever value you like, for example: buildNumber = DEV. This will make the buildNumber property available during the build process and populate this property, however it will not be updated from your SCM.

We are using the first workaround for the multi-module maven project, since we also encountered similar limitations using the buildnumber-maven-plugin. We also use solution 2 when we need to run the integration test in IntelliJ, since the buildNumber property is required by our code to display version information if we give it any value that you like.

I hope this is somewhat useful for you, the only real solution for IntelliJ’s internal internal integration system is to have some idea of ​​buildnumber-maven-plugin and set the correct properties for the environment during the build process.

+8
source

All Articles