You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "KARR, DAVID (ATTCINW)" <dk...@att.com> on 2009/12/21 00:44:42 UTC

Best way to have script fail if not using new enough JDK?

I need to have my Ant script abort if the current JDK version is older
than the project needs (1.6).

I noticed a "JavaVersionTask" sample at <http://onjava.com/lpt/a/6264>
which would probably help, but I wonder if there's an easier way since
that article was written (4 years ago).

I can see the possibility of doing this with a Groovy scriptcondition to
set the property to check, but I can't figure out how I can get Groovy
to set Ant properties, or to return a value that would set the property.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Best way to have script fail if not using new enough JDK?

Posted by "Moore, Kent" <Ke...@fnis.com>.
We enforce the java version using one of these two routines in our init target:

        <!-- check for java version and fail build immediately if not using the correct version -->
        <echo message="Java Version: ${java.version}"/>
        <echo message="Java home: ${java.home}"/>
        <fail message="Unsupported Java version: ${java.version}. Make sure that the version of the Java compiler is 1.6.">
            <condition>
                <not>
                    <contains string="${java.version}" substring="1.6" casesensitive="false" />
                </not>
            </condition>
        </fail>


or, to allow a minimum java version - 

        <!-- check for java version and fail build immediately if not using the correct version -->
        <echo message="Java Version: ${java.version}"/>
        <echo message="Java home: ${java.home}"/>
        <fail message="Unsupported Java version: ${java.version}. Please make sure the version of the Java compiler is 1.5 (5.0) or greater.">
            <condition>
                <not>
                    <or>
                        <contains string="${java.version}" substring="1.5" casesensitive="false" />
                        <contains string="${java.version}" substring="1.6" casesensitive="false" />
                    </or>
                </not>
            </condition>
        </fail>




-----Original Message-----
From: KARR, DAVID (ATTCINW) [mailto:dk068x@att.com]
Sent: Sun 12/20/2009 6:44 PM
To: Ant Users List
Subject: Best way to have script fail if not using new enough JDK?
 
I need to have my Ant script abort if the current JDK version is older
than the project needs (1.6).

I noticed a "JavaVersionTask" sample at <http://onjava.com/lpt/a/6264>
which would probably help, but I wonder if there's an easier way since
that article was written (4 years ago).

I can see the possibility of doing this with a Groovy scriptcondition to
set the property to check, but I can't figure out how I can get Groovy
to set Ant properties, or to return a value that would set the property.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org





_____________

The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
_____________


AW: Best way to have script fail if not using new enough JDK?

Posted by Ja...@rzf.fin-nrw.de.
<fail message="Not a Java 1.6+">
  <not><available classname="java.util.ServiceLoader"/></not>
</fail> 

(see target "check_for_optional_packages" in Ants own buildfile)


Jan

>-----Ursprüngliche Nachricht-----
>Von: KARR, DAVID (ATTCINW) [mailto:dk068x@att.com] 
>Gesendet: Montag, 21. Dezember 2009 00:45
>An: Ant Users List
>Betreff: Best way to have script fail if not using new enough JDK?
>
>I need to have my Ant script abort if the current JDK version is older
>than the project needs (1.6).
>
>I noticed a "JavaVersionTask" sample at <http://onjava.com/lpt/a/6264>
>which would probably help, but I wonder if there's an easier way since
>that article was written (4 years ago).
>
>I can see the possibility of doing this with a Groovy 
>scriptcondition to
>set the property to check, but I can't figure out how I can get Groovy
>to set Ant properties, or to return a value that would set the 
>property.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org