我有一个属性app.version,它设置为1.2.0(当然,总是在变化),需要创建一个名为“something-ver-1_2_0”的zip文件。这可能吗?

最佳答案

您可以使用pathconvert任务替换“”。与“_”并分配给新属性:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <property name="app.version" value="1.2.0"/>

    <pathconvert property="app.version.underscore" dirsep="" pathsep="" description="Replace '.' with '_' and assign value to new property">
        <path path="${app.version}" description="Original app version with dot notation" />

        <!--Pathconvert will try to add the root directory to the "path", so replace with empty string -->
        <map from="${basedir}" to="" />

        <filtermapper>
            <replacestring from="." to="_"/>
        </filtermapper>

    </pathconvert>

    <echo>${app.version} converted to ${app.version.underscore}</echo>
</project>

09-30 14:18
查看更多