maven-android-plugin 传递构建属性

发布于 2024-12-03 15:16:48 字数 438 浏览 0 评论 0原文

我在资产文件夹中有一个属性文件,我想在项目构建时覆盖此属性文件中的值。 像 mvn clean install -Durl=https://xyx.xom 一样?

EX:assets/my_prop.properties

#  my_server_url=http://www.test.com/ 
change to 
my_server_url=${url}

我想在构建时替换 my_server_url 值,我做了什么: mvn clean install -Durl=http://xys.com

但它没有替换,我如何在执行以下操作时替换 my_server_url建造

I have a property file in asset folder, i want to override the values in this property file at project build time.
like mvn clean install -Durl=https://xyx.xom?

EX: assets/my_prop.properties

#  my_server_url=http://www.test.com/ 
change to 
my_server_url=${url}

i want to replace the my_server_url value at the build time what i did:
mvn clean install -Durl=http://xys.com

but it's not replacing,how can i replace the my_server_url when doing the buid

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩起发的微风 2024-12-10 15:16:48

在您的 pom 中,在 节点中,您需要启用如下过滤:

<build>
    <resources>
        <resource>
            <directory>assets</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>assets</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>**/*.properties</exclude>
            </excludes>
        </resource>
    </resources>

    ...

</build>

完成后,您可以通过运行进行测试:

mvn resources:resource -Durl=http://www.test.com/

请注意,排除部分在那里,因为您不这样做不希望 Maven 过滤 asset 目录中可能存在的任何二进制文件。如果您没有该部分,它通常会通过尝试过滤二进制文件而最终损坏它们。

通过这种配置方式,过滤后的属性文件将进入您可能不想要的目标/类。您可以通过添加 节点来更改它。有关配置资源的更多说明,请参阅此链接

In your pom, within the <build> node, you'll need to enable filtering like this:

<build>
    <resources>
        <resource>
            <directory>assets</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>assets</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>**/*.properties</exclude>
            </excludes>
        </resource>
    </resources>

    ...

</build>

Once that's done, you can test by running:

mvn resources:resource -Durl=http://www.test.com/

Note that the excludes portion is there because you don't want Maven to filter through any binary files that you may have in the assets directory. If you don't have that portion, it usually ends up corrupting any binary files by attempting to filter them.

With the way that this is configured, the filtered property file will go into target/classes, which you probably don't want. You can change that by adding a <targetPath> node. See this link for more notes on configuring resources.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文