开发者

maven-android-plugin passing build properties

开发者 https://www.devze.com 2023-04-03 19:15 出处:网络
I have a property file in asset folder, i want to override the values in this property file at project build time.

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=htt开发者_开发知识库p://xys.com

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号