Android: Maven final archive name

1.1k views Asked by At

At the end of a maven mvn clean install run, the created artifacts are automatically installed in the repository by the maven-install-plugin:

[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ project ---
[INFO] Installing C:\Users\mannaz\workspace\project\target\project-0.1.1-test.apk to C:\Users\mannaz\.m2\repository\at\mannaz\android\project\0.1.1\project-0.1.1.apk
[INFO] Installing C:\Users\mannaz\workspace\project\pom.xml to C:\Users\mannaz\.m2\repository\at\mannaz\android\project\0.1.1\project-0.1.1.pom
[INFO] Installing C:\Users\mannaz\workspace\project\target\project-0.1.1-test.jar to C:\Users\mannaz\.m2\repository\at\mannaz\android\project\0.1.1\project-0.1.1.jar

Unfortunately the final apk filename is renamed during this process (project-0.1.1-test.apk>>project-0.1.1.apk).

Initially the name of the apk file is set via

<finalName>${project.artifactId}-${project.version}-${webservice.target}</finalName>

How can I specify the final name of the apk file in the build archive without overriding the <version/> attribute itself?

1

There are 1 answers

0
yorkw On BEST ANSWER

Reason:

Running mvn clean install -X cause Maven execute default-install goal at the end of the build life cycle, which use the default groupId:artifactId:packaging:version install the generated apk (I use abc-123 as the final name in this example):

[INFO] --- maven-install-plugin:2.1:install (default-install) @ myapp ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-install-plugin:2.1:install from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-install-plugin:2.1, parent: sun.misc.Launcher$AppClassLoader@11b86e7]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-install-plugin:2.1:install' with basic configurator -->
[DEBUG]   (f) artifact = com.mycompany:myapp:apk:1.2.2-SNAPSHOT
[DEBUG]   (f) attachedArtifacts = [com.mycompany:myapp:jar:1.2.2-SNAPSHOT]
[DEBUG]   ... ...
[DEBUG] -- end configuration --
[INFO] Installing C:\workspace\myapp\target\abc-123.apk to c:\maven\repository\com\mycompany\myapp\1.2.2-SNAPSHOT\myapp-1.2.2-SNAPSHOT.apk
[INFO] ... ...

Solution:

This default artifact install is AFAIK neither avoidable nor modifiable, and the <finalName> doesn't take any effect on the target file name (which use a fixed pattern artifactId-version-classifier.packaging) during the default-install goal execution. The solution is attach extra artifact to the build life cycle, depend on you demand (If you only need add some suffix behind myapp-1.2.2-SNAPSHOT), the easiest way is define a classifier in android-maven-plugin configuration:

<plugin>
  <groupId>com.jayway.maven.plugins.android.generation2</groupId>
  <artifactId>android-maven-plugin</artifactId>
  <extensions>true</extensions>
  <configuration>
    <classifier>test</classifier>
    ... ...
  </configuration>
</plugin>

This will cause both myapp-1.2.2-SNAPSHOT.apk and myapp-1.2.2-SNAPSHOT-test.apk get installed into maven repository:

[INFO] --- maven-install-plugin:2.1:install (default-install) @ myapp ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-install-plugin:2.1:install from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-install-plugin:2.1, parent: sun.misc.Launcher$AppClassLoader@11b86e7]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-install-plugin:2.1:install' with basic configurator -->
[DEBUG]   (f) artifact = com.mycompany:myapp:apk:1.2.2-SNAPSHOT
[DEBUG]   (f) attachedArtifacts = [com.mycompany:myapp:jar:1.2.2-SNAPSHOT, com.mycompany:myapp:apk:test:1.2.2-SNAPSHOT]
[DEBUG]   ... ...
[DEBUG] -- end configuration --
[INFO] Installing C:\workspace\myapp\target\abc-123.jar to c:\maven\repository\com\mycompany\myapp\1.2.2-SNAPSHOT\myapp-1.2.2-SNAPSHOT.apk
[INFO] ... ...
[INFO] Installing C:\workspace\myapp\target\abc-123.apk to c:\maven\repository\com\mycompany\myapp\1.2.2-SNAPSHOT\myapp-1.2.2-SNAPSHOT-test.apk