Le 7 août 2012 à 21:15, Steve Amerige a écrit :

> On 8/6/2012 9:04 AM, Nicolas Lalevée wrote:
>> There is a possible hack I guess.
>> There is a deprecated option to typedef : reverseLoader. If set to true, the 
>> classloader inheritance is inverted.
>> I don't know why it is deprecated but surely for a good reason, so use it at 
>> your own risk
> 
> The code shown below _does_ work!  Thank you very much!  Is this the best way 
> to take care of this need for both Ant 1.7 and Ant 1.8?  Specifically, what 
> about using *<classloader>* task as an alternative?  I couldn't find examples 
> of how *<classloader>* is used, but saw it in the 1.8 source code?

hum, I didn't know about that task. As you can see, it is marked as 
experimental, so its use is not more recommended than the reverseloader 
attribute. Actually looking at the actual implementation, reverseloader looks 
cleaner than this task.

> If there is a better way to give my classpath priority other than the 
> *reverseloader *trick, can someone provide example code that works in both 
> Ant 1.7 and 1.8 (even if conditional code is used) so that I get it right?

I don't think there a proper official way to do so.

I have looked into the history of Ant, and it seems that this attribute 
reverseloader was introduced already deprecated. At that time, the way 
classloading was happening has being reversed from "child first" to the current 
one "parent first". Some task were relying on the "child first" behavior so an 
attribute was added for the desperate cases.
Then, only speaking for myself and not for the Ant committers, I don't think 
"reverse" behavior to be ugly. We gain a fine control of the classloading, just 
like we do while using inheritance in Java.
And considering Ant backward compatibility policy, I wouldn't worry much of 
that attribute to be removed soon, even deprecated.

So it is not clean, but clean enough for me to use on edge cases like yours.

Nicolas


> 
> Many thanks!
> 
> Steve Amerige
> SAS Institute, Deployment Developer
> 
> *build.xml:*
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <project name="Ant" default="main" basedir=".">
> 
> <taskdef
>   name="groovy"
>   classname="org.codehaus.groovy.ant.Groovy"
>   classpath="C:/groovy-2.0.1/embeddable/groovy-all-2.0.1.jar"
>   reverseloader="true"/>
> 
> <target name="main">
> <echo message="ant: ${ant.version}"/>
> <groovy>
>        println GroovySystem.getVersion()
> </groovy>
> </target>
> 
> </project>**
> 
> *output with Ant 1.7.1:*
> 
> *without reverseloader="true":*
> 
> main:
>     [echo] ant: Apache Ant version 1.7.1 compiled on June 27 2008
>   [groovy] 1.7.10
> BUILD SUCCESSFUL
> 
> *with reverseloader="true":*
> 
>  [taskdef] The reverseloader attribute is DEPRECATED. It will be removed
> main:
>     [echo] ant: Apache Ant version 1.7.1 compiled on June 27 2008
>   [groovy] 2.0.1
> BUILD SUCCESSFUL
> 
> *output with Ant 1.8.4:*
> 
> *without reverseloader="true":*
> 
> main:
>     [echo] ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
>   [groovy] 1.7.10
> BUILD SUCCESSFUL
> 
> *with reverseloader="true":*
> 
>  [taskdef] The reverseloader attribute is DEPRECATED. It will be removed
> main:
>     [echo] ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
>   [groovy] 2.0.1
> BUILD SUCCESSFUL


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

Reply via email to