Can Ant expand environment variables from a properties file?

前端 未结 1 1233
盖世英雄少女心
盖世英雄少女心 2021-02-19 22:03

I have a question regarding Ant and its treatment of environment variables. To illustrate I have a small sample.

Given the Ant build file test.xml:

相关标签:
1条回答
  • 2021-02-19 22:22

    You need to read the test.props property file after the environment - you could do so using another property task, i.e. add

    <property file="test.props" />
    

    after your existing property environment task.

    In full:

    <property environment="env" />
    <property file="test.props" />
    
    <target name="testProps">
        <echo message="${env.MyEnvVar}"/>
        <echo message="${MY_PROPERTY}"/>
    </target>
    

    When you supply the properties file on the command line this gets processed before the content of the build, but at that time ${env.MyEnvVar} is not yet set.

    0 讨论(0)
提交回复
热议问题