4

在 mavenmvn 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>

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

4

1 回答 1

2

原因:

运行mvn clean install -X原因 Maven在构建生命周期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解决方案是在构建生命周期中附加额外的工件,取决于您的需求(如果您只需要在后面添加一些后缀),最简单的方法是在 android-maven-plugin 配置myapp-1.2.2-SNAPSHOT中定义一个分类器:

<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
于 2012-10-16T23:04:20.637 回答