Android:Maven最终归档名称

时间:2012-10-16 10:08:47

标签: android maven jenkins android-build maven-install-plugin

在maven mvn clean install运行结束时,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

不幸的是,在此过程中重命名了最终的apk文件名(project-0.1.1-test.apk>> project-0.1.1.apk)。

最初,apk文件的名称是通过

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

如何在不覆盖<version/>属性本身的情况下在构建存档中指定apk文件的最终名称?

1 个答案:

答案 0 :(得分:2)

原因:

运行mvn clean install -X导致Maven在build life cycle结束时执行default-install目标,该目标使用默认的groupId:artifactId:packaging:version安装生成的apk(我使用{{1作为此示例中的最终名称):

abc-123

解决方案:

此默认工件安装是AFAIK既不可避免也不可修改,[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] ... ... 对默认安装目标期间的目标文件名(使用固定模式<finalName>)不会产生任何影响执行。解决方案是将额外的工件附加到构建生命周期,取决于您的需求(如果您只需要在artifactId-version-classifier.packaging后面添加一些后缀),最简单的方法是在android-maven-plugin配置中定义classifier

myapp-1.2.2-SNAPSHOT

这将导致myapp-1.2.2-SNAPSHOT.apk和myapp-1.2.2-SNAPSHOT-test.apk安装到maven存储库中:

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