Can Ant properties resolve other properties?

前端 未结 2 1247
北恋
北恋 2021-02-19 03:48

Can Ant properties set via properties file, resolve other properties from properties files?

For example, I can do this:



        
相关标签:
2条回答
  • 2021-02-19 04:25

    A simpler solution for this task would be the usage of Ant-contrib Tasks: Propertycopy.

    From the manual:

    <property name="org" value="MyOrg" />
    <property name="org.MyOrg.DisplayName" value="My Organiziation" />
    <propertycopy name="displayName" from="org.${org}.DisplayName" />
    
    Sets displayName to "My Organiziation".
    
    0 讨论(0)
  • 2021-02-19 04:43

    Ant does support in-file property expansion, see the Property File section in the manual for the Property task.

    The following example shows properties getting resolved:

    • within a single properties file
    • from one properties file in another properties file
    • within a build file

    First properties file:

    $ cat props1.properties
    prop1=world
    prop2=hello ${prop1}
    

    Second properties file:

    $ cat props2.properties
    prop3=goodbye ${prop1}
    

    Build file:

    <project default="test">
      <property file="props1.properties"/>
      <property file="props2.properties"/>
      <property name="prop4" value="${prop3}, good luck"/>
      <target name="test">
        <echo message="prop1 = ${prop1}"/>
        <echo message="prop2 = ${prop2}"/>
        <echo message="prop3 = ${prop3}"/>
        <echo message="prop4 = ${prop4}"/>
      </target>
    </project>
    

    Output:

    $ ant
    Buildfile: build.xml
    
    test:
         [echo] prop1 = world
         [echo] prop2 = hello world
         [echo] prop3 = goodbye world
         [echo] prop4 = goodbye world, good luck
    
    BUILD SUCCESSFUL
    Total time: 0 seconds
    

    Is there another kind of property resolution that is not working for you?

    Edit

    Following your comment, I now understand that you are using the -propertyfile command line option to specify a property file for Ant to load (rather than specifying the file in the buildfile itself, as I did above).

    I did quick test with this and find that Ant 1.7.1 did not do in-file property expansion on files loaded using that command line option. But Ant 1.8.2 does.

    This is Ant Bug 18732. You should be able to resolve by updating your version of Ant.

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