Android:Maven最终归档名称

在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文件的最终名称属性本身?

最佳答案 原因:

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

[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] ... ...

解:

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

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

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

[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
点赞