如何使用maven-android-plugin项目的外部settings.xml中的maven设置?

时间:2012-06-06 21:16:59

标签: android maven-3

我创建了一个Android Maven项目,正如本文(link to post)中所述。我使用的是最后一个原型:android-release。

所以一切正常,除非我想发布一个版本,我无法弄清楚如何传递证书属性。我创建了一个settings.xml,其中包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
    <profile>
        <id>android-debug</id>
        <properties>
            <sign.keystore>/Users/me/.android/debug.keystore</sign.keystore>
            <sign.alias>androiddebugkey</sign.alias>
            <sign.storepass>android</sign.storepass>
            <sign.keypass>android</sign.keypass>
        </properties>
    </profile>

    <profile>
        <id>android-release</id>
        <properties>
            <sign.keystore>/Users/me/myKeystore.keystore</sign.keystore>
            <sign.alias>myAlias</sign.alias>
            <sign.storepass><![CDATA[myPassword]]></sign.storepass>
            <sign.keypass><![CDATA[myPassword]]></sign.keypass>
        </properties>
    </profile>

</profiles>

然后我跑:

mvn -s setttings.xml clean release:prepare release:perform -Pandroid-release

但我一直忽略android-release配置文件中定义的值。

任何想法如何让这个工作?当我跑步时:

mvn -s setttings.xml clean install -Pandroid-release,release

它构建一个apk并使用正确的证书进行signes。那么也许它只是maven-enforcer-plugin,它无法从settings.xml中读取属性?

1 个答案:

答案 0 :(得分:2)

  

mvn -s setttings.xml clean release:prepare release:perform -Pandroid-release

我不知道为什么它一直忽略android-release配置文件中定义的值。

但是,如果你使用maven-release-plugin,我们用来实现你想要的正常方式是将以下设置添加到你想在发布阶段触发的配置文件中:

<profile>
    <id>android-release</id>
    <properties>
        <sign.keystore>/Users/me/myKeystore.keystore</sign.keystore>
        <sign.alias>myAlias</sign.alias>
        <sign.storepass><![CDATA[myPassword]]></sign.storepass>
        <sign.keypass><![CDATA[myPassword]]></sign.keypass>
    </properties>
    <!-- via this activation the profile is automatically used when the release 
        is done with the maven release plugin -->
    <activation>
        <property>
            <name>performRelease</name>
            <value>true</value>
        </property>
    </activation>
</profile>

现在,如果您执行mvn -s setttings.xml clean release:prepare release:perform,maven-release-plugin会自动选择profile android-release

请注意,在发布阶段会自动激活配置文件,如果没有涉及maven-release-plugin,您仍然可以使用经典方式mvn -s setttings.xml clean install -Pandroid-release使构建过程使用特定的profile android-release

查看maven-release-plugin doc了解详情。