tkr
tkr

Reputation: 93

ant property conditional on another property

I would like to do the following in ant

if javac.version >= 1.7
then
  <property name="myproperty" value="somevalue"/>
else
  <property name="myproperty" value="someothervalue"/>
endif

Looks simple enough but not familiar enough with ant to do this

Any assistance appreciated

Upvotes: 2

Views: 83

Answers (1)

Alexey Gavrilov
Alexey Gavrilov

Reputation: 10853

You can use the condition task to check if the contents of the java version system property contains the version you need. Here is an example:

<project name="test" default="target">
    <target name="target">
        <condition property="property" value="value1" else="value2">
            <contains string="${java.version}" substring="1.7"/>
        </condition>
        <echo>Java version: ${java.version}. Result: ${property}</echo>
    </target>
</project>

Output:

Java version: 1.7.0_60. Result: value1

Upvotes: 2

Related Questions