Maven过滤 [英] Maven Filtering

查看:107
本文介绍了Maven过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maven(3.x)在哈德森内部构建Android应用程序.在构建过程中,我使用过滤/配置文件对strings.xml文件进行文本替换.

I am using Maven (3.x) to build an Android application within Hudson. I use filtering/profiles to do text substition of the strings.xml file as part of the build.

因此在strings.xml中,我将输入诸如:

So within the strings.xml, I will have entries such as:

<string name="app_name">${app_name}</string>

在pom.xml文件中,我有一些配置文件条目:

Within the pom.xml file, I have profile entries:

 <profiles>
    <profile>
        <id>local</id>
        <properties>
            <app_env>local</app_env>
       <app_name>Acme-loc</app_name>
        </properties>
    </profile>  
    <profile>
        <id>dev</id>
        <properties>
            <app_env>dev</app_env>
       <app_name>Acme-dev</app_name>
        </properties>
    </profile>      
    ....

当我查看* .apk时,正确替换了strings.xml文件.但是,当安装在设备中时,我看到$ {app_name},这使我相信替换是在应用程序编译之后发生的.我可以指定替换发生在构建的哪一步吗?

When I look inside the *.apk, the strings.xml file is substituted correctly. However, when installed in device, I see ${app_name} which leads me to believe that the substitution is happening after the compile of app. Can I specify which step of the build the substitution happens?

推荐答案

在标准的Maven构建中,资源过滤发生在进程资源中,该资源在编译之前,而在包之前.没有更多有关如何设置资源过滤以及如何构建程序包的详细信息,很难说更多.

In a standard maven build, resource filtering happens at process-resources, which comes before compile, which comes before package. It's hard to say more without more details about how you have resource filtering set up and how your package is built.

编辑:您似乎正在使用android插件的之后的版本.您需要确保android目标在之后运行.资源过滤发生,并且指向输出的strings.xml文件,而不是源文件.

It looks like you're probably generating the R.java file using the android plugin's generate-sources goal, right? That's most likely bound to the generate-sources phase. Your strings.xml doesn't get filtered until the process-resources phase, which comes later in the build. You need to make sure that the android goal runs after the resource filtering happens and that it points at the output strings.xml file, not the source file.

这篇关于Maven过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆