【问题标题】:Android: Maven final archive nameAndroid:Maven 最终存档名称
【发布时间】:2012-10-16 10:08:46
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    原因:

    运行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 既无法避免也无法修改,并且在默认安装目标执行期间,&lt;finalName&gt; 不会对目标文件名(使用固定模式 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-23
      • 2017-05-19
      • 2011-05-13
      • 1970-01-01
      • 2011-12-03
      相关资源
      最近更新 更多