You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Steve Amerige <St...@sas.com> on 2012/08/03 19:57:44 UTC
How to Execute Groovy 2.0 Code from an Ant File that has Groovy 1.7
Classpath
Hi all,
My Ant script is being called with an environment including the
classpath that includes the folder containing the groovy-all-1.7.10.jar
file. I want to execute Groovy 2.0 code from my Ant script. I cannot
change any aspect of how my Ant script is called. I must limit my
solution to that which I can put into my own Ant script.
My challenge is to figure a way to run groovy 2.0 code. My attempt
below fails to do this. I'm hoping someone will have a solution.
Ideally, it will NOT involve using *exec *because in the groovy code I
will be using AntBuilder to access various tasks, macros, etc. that are
defined back on the Ant side and I want logging information to go to the
same logfile as well.
*Can anyone think of a way to execute some Groovy 2.0 code given that
the classpath already includes a 1.7 Groovy jar file?*
Thanks,
Steve Amerige
SAS Institute, Deployment Developer
Note below that the Groovy system version is 1.7.10, not 2.0.1.
<?xml version="1.0" encoding="UTF-8"?>
<project name="Ant" default="main" basedir=".">
<path id="my.classpath">
<fileset dir="C:/test/groovy-2.0.1/embeddable">
<include name="groovy-all-2.0.1.jar" />
</fileset>
</path>
<taskdef
name="groovy"
classname="org.codehaus.groovy.ant.Groovy"
classpath="C:/test/groovy-2.0.1/embeddable/groovy-all-2.0.1.jar"/>
<target name="main">
<groovy classpathref="my.classpath">
println GroovySystem.getVersion()
println GroovySystem.class.getClassLoader().getURLs().join("\n")
</groovy>
</target>
</project>
Buildfile: C:\test\build.xml
main:
[groovy] *1.7.10*
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-antlr.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-bcel.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-bsf.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-log4j.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-oro.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-regexp.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-resolver.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-commons-logging.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-commons-net.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jai.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-javamail.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jdepend.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jmf.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jsch.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-junit.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-launcher.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-netrexx.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-nodeps.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-starteam.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-stylebook.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-swing.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-trax.jar
[groovy]
file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-weblogic.jar
[groovy]
file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/84/1/.cp/lib/remoteAnt.jar
[groovy]
file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/772/1/.cp/lib/antdebug.jar
[groovy]
file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/772/1/.cp/lib/remote.jar
[groovy]
file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/1140/1/.cp/antlibs/remoteAnt.jar
[groovy] file:/C:/Program%20Files/Java/jdk1.6.0_24/lib/tools.jar
[groovy]
file:/C:/eclipse/plugins/org.eclipse.swt.win32.win32.x86_64_3.6.2.v3659c.jar
[groovy] file:/C:/test/ant-contrib/ant-contrib.jar
[groovy]
file:/C:/eclipse/plugins/org.codehaus.groovy_1.7.10.xx-20110918-1400-e36/lib/groovy-all-1.7.10.jar
[groovy] file:/C:/test/json_0.2.0.0_SAS_20100917120500/JSON.jar
BUILD SUCCESSFUL
Total time: 1 second
Re: How to Execute Groovy 2.0 Code from an Ant File that has Groovy
1.7 Classpath
Posted by Steve Amerige <St...@sas.com>.
Hi Nicolas and all,
On 8/7/2012 3:58 PM, Nicolas Lalevée wrote:
> 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.
Thanks again for your confirmation regarding the use of the
*reverseloader *attribute. We will be using it and hope it is not
removed in the future!
Regarding the log message:
The reverseloader attribute is DEPRECATED. It will be removed
Is there a way to prevent this from being written to the logs? I tried
using the recorder task, but that didn't work:
<record name="output.log" action="stop"/>
<taskdef name="groovy" ... reverseloader="true"/>
If there is no reasonable way to prevent it from being emitted, we'll
just need to document it as a message to be ignored.
Many thanks again for your input and help!
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
Re: How to Execute Groovy 2.0 Code from an Ant File that has Groovy 1.7 Classpath
Posted by Nicolas Lalevée <ni...@hibnet.org>.
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-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How to Execute Groovy 2.0 Code from an Ant File that has Groovy
1.7 Classpath
Posted by Steve Amerige <St...@sas.com>.
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?
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?
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
Re: How to Execute Groovy 2.0 Code from an Ant File that has Groovy 1.7 Classpath
Posted by Peter West <li...@pbw.id.au>.
Failing that, define propertysets with the properties you need to propagate, then invoke ant via a java task with a fork, and the set of environment variables you want (including classpath.)
Peter West
"...you will find rest for your souls. For my yoke is easy, and my burden is light."
On 06/08/2012, at 11:04 PM, Nicolas Lalevée <ni...@hibnet.org> wrote:
>
> Le 6 août 2012 à 14:37, Steve Amerige a écrit :
>
>> Some more info on this problem:
>>
>> The issue is is a ClassLoader delegation model <http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html> problem. If the classpath has in it a path to Groovy 1.7.10 (as it does), then even if I explicitly add the classpath in Ant as I do below, the 1.7.10 version will still be used because it has already been loaded. The only solutions I can think of include:
>>
>> 1. Export all Ant properties and the current classpath to a file. Use exec to run ant with a classpath that puts the Groovy 2.0.1 directory before the other directories in the classpath. Then, load the ant properties and continue.
>>
>> 2. Discover if there is any way of doing dynamic classloading that gets past the delegation model problem.
>
> 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 ;)
>
> Nicolas
>
>>
>> If you have any ideas, please send them my way! By mid-week, I'll wind up doing whatever the best solution there is for this problem, even if it is (1) above.
>>
>> Enjoy,
>> Steve Amerige
>> SAS Institute, Deployment Developer
>>
>> On 8/3/2012 1:57 PM, Steve Amerige wrote:
>>> Hi all,
>>>
>>> My Ant script is being called with an environment including the classpath that includes the folder containing the groovy-all-1.7.10.jar file. I want to execute Groovy 2.0 code from my Ant script. I cannot change any aspect of how my Ant script is called. I must limit my solution to that which I can put into my own Ant script.
>>>
>>> My challenge is to figure a way to run groovy 2.0 code. My attempt below fails to do this. I'm hoping someone will have a solution. Ideally, it will NOT involve using *exec *because in the groovy code I will be using AntBuilder to access various tasks, macros, etc. that are defined back on the Ant side and I want logging information to go to the same logfile as well.
>>>
>>> *Can anyone think of a way to execute some Groovy 2.0 code given that the classpath already includes a 1.7 Groovy jar file?*
>>>
>>> Thanks,
>>> Steve Amerige
>>> SAS Institute, Deployment Developer
>>>
>>> Note below that the Groovy system version is 1.7.10, not 2.0.1.
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>>
>>> <project name="Ant" default="main" basedir=".">
>>>
>>> <path id="my.classpath">
>>> <fileset dir="C:/test/groovy-2.0.1/embeddable">
>>> <include name="groovy-all-2.0.1.jar" />
>>> </fileset>
>>> </path>
>>>
>>> <taskdef
>>> name="groovy"
>>> classname="org.codehaus.groovy.ant.Groovy"
>>> classpath="C:/test/groovy-2.0.1/embeddable/groovy-all-2.0.1.jar"/>
>>>
>>> <target name="main">
>>> <groovy classpathref="my.classpath">
>>> println GroovySystem.getVersion()
>>> println GroovySystem.class.getClassLoader().getURLs().join("\n")
>>> </groovy>
>>> </target>
>>>
>>> </project>
>>>
>>>
>>> Buildfile: C:\test\build.xml
>>> main:
>>> [groovy] *1.7.10*
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-antlr.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-bcel.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-bsf.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-log4j.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-oro.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-regexp.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-resolver.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-commons-logging.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-commons-net.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jai.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-javamail.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jdepend.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jmf.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jsch.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-junit.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-launcher.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-netrexx.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-nodeps.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-starteam.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-stylebook.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-swing.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-trax.jar
>>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-weblogic.jar
>>> [groovy] file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/84/1/.cp/lib/remoteAnt.jar
>>> [groovy] file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/772/1/.cp/lib/antdebug.jar
>>> [groovy] file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/772/1/.cp/lib/remote.jar
>>> [groovy] file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/1140/1/.cp/antlibs/remoteAnt.jar
>>> [groovy] file:/C:/Program%20Files/Java/jdk1.6.0_24/lib/tools.jar
>>> [groovy] file:/C:/eclipse/plugins/org.eclipse.swt.win32.win32.x86_64_3.6.2.v3659c.jar
>>> [groovy] file:/C:/test/ant-contrib/ant-contrib.jar
>>> [groovy] file:/C:/eclipse/plugins/org.codehaus.groovy_1.7.10.xx-20110918-1400-e36/lib/groovy-all-1.7.10.jar
>>> [groovy] file:/C:/test/json_0.2.0.0_SAS_20100917120500/JSON.jar
>>> BUILD SUCCESSFUL
>>> Total time: 1 second
>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> 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
Re: How to Execute Groovy 2.0 Code from an Ant File that has Groovy 1.7 Classpath
Posted by Nicolas Lalevée <ni...@hibnet.org>.
Le 6 août 2012 à 14:37, Steve Amerige a écrit :
> Some more info on this problem:
>
> The issue is is a ClassLoader delegation model <http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html> problem. If the classpath has in it a path to Groovy 1.7.10 (as it does), then even if I explicitly add the classpath in Ant as I do below, the 1.7.10 version will still be used because it has already been loaded. The only solutions I can think of include:
>
> 1. Export all Ant properties and the current classpath to a file. Use exec to run ant with a classpath that puts the Groovy 2.0.1 directory before the other directories in the classpath. Then, load the ant properties and continue.
>
> 2. Discover if there is any way of doing dynamic classloading that gets past the delegation model problem.
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 ;)
Nicolas
>
> If you have any ideas, please send them my way! By mid-week, I'll wind up doing whatever the best solution there is for this problem, even if it is (1) above.
>
> Enjoy,
> Steve Amerige
> SAS Institute, Deployment Developer
>
> On 8/3/2012 1:57 PM, Steve Amerige wrote:
>> Hi all,
>>
>> My Ant script is being called with an environment including the classpath that includes the folder containing the groovy-all-1.7.10.jar file. I want to execute Groovy 2.0 code from my Ant script. I cannot change any aspect of how my Ant script is called. I must limit my solution to that which I can put into my own Ant script.
>>
>> My challenge is to figure a way to run groovy 2.0 code. My attempt below fails to do this. I'm hoping someone will have a solution. Ideally, it will NOT involve using *exec *because in the groovy code I will be using AntBuilder to access various tasks, macros, etc. that are defined back on the Ant side and I want logging information to go to the same logfile as well.
>>
>> *Can anyone think of a way to execute some Groovy 2.0 code given that the classpath already includes a 1.7 Groovy jar file?*
>>
>> Thanks,
>> Steve Amerige
>> SAS Institute, Deployment Developer
>>
>> Note below that the Groovy system version is 1.7.10, not 2.0.1.
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>> <project name="Ant" default="main" basedir=".">
>>
>> <path id="my.classpath">
>> <fileset dir="C:/test/groovy-2.0.1/embeddable">
>> <include name="groovy-all-2.0.1.jar" />
>> </fileset>
>> </path>
>>
>> <taskdef
>> name="groovy"
>> classname="org.codehaus.groovy.ant.Groovy"
>> classpath="C:/test/groovy-2.0.1/embeddable/groovy-all-2.0.1.jar"/>
>>
>> <target name="main">
>> <groovy classpathref="my.classpath">
>> println GroovySystem.getVersion()
>> println GroovySystem.class.getClassLoader().getURLs().join("\n")
>> </groovy>
>> </target>
>>
>> </project>
>>
>>
>> Buildfile: C:\test\build.xml
>> main:
>> [groovy] *1.7.10*
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-antlr.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-bcel.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-bsf.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-log4j.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-oro.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-regexp.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-resolver.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-commons-logging.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-commons-net.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jai.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-javamail.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jdepend.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jmf.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jsch.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-junit.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-launcher.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-netrexx.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-nodeps.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-starteam.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-stylebook.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-swing.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-trax.jar
>> [groovy] file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-weblogic.jar
>> [groovy] file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/84/1/.cp/lib/remoteAnt.jar
>> [groovy] file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/772/1/.cp/lib/antdebug.jar
>> [groovy] file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/772/1/.cp/lib/remote.jar
>> [groovy] file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/1140/1/.cp/antlibs/remoteAnt.jar
>> [groovy] file:/C:/Program%20Files/Java/jdk1.6.0_24/lib/tools.jar
>> [groovy] file:/C:/eclipse/plugins/org.eclipse.swt.win32.win32.x86_64_3.6.2.v3659c.jar
>> [groovy] file:/C:/test/ant-contrib/ant-contrib.jar
>> [groovy] file:/C:/eclipse/plugins/org.codehaus.groovy_1.7.10.xx-20110918-1400-e36/lib/groovy-all-1.7.10.jar
>> [groovy] file:/C:/test/json_0.2.0.0_SAS_20100917120500/JSON.jar
>> BUILD SUCCESSFUL
>> Total time: 1 second
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How to Execute Groovy 2.0 Code from an Ant File that has Groovy
1.7 Classpath
Posted by Steve Amerige <St...@sas.com>.
Some more info on this problem:
The issue is is a ClassLoader delegation model
<http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html>
problem. If the classpath has in it a path to Groovy 1.7.10 (as it
does), then even if I explicitly add the classpath in Ant as I do below,
the 1.7.10 version will still be used because it has already been
loaded. The only solutions I can think of include:
1. Export all Ant properties and the current classpath to a file. Use
exec to run ant with a classpath that puts the Groovy 2.0.1 directory
before the other directories in the classpath. Then, load the ant
properties and continue.
2. Discover if there is any way of doing dynamic classloading that gets
past the delegation model problem.
If you have any ideas, please send them my way! By mid-week, I'll wind
up doing whatever the best solution there is for this problem, even if
it is (1) above.
Enjoy,
Steve Amerige
SAS Institute, Deployment Developer
On 8/3/2012 1:57 PM, Steve Amerige wrote:
> Hi all,
>
> My Ant script is being called with an environment including the
> classpath that includes the folder containing the
> groovy-all-1.7.10.jar file. I want to execute Groovy 2.0 code from my
> Ant script. I cannot change any aspect of how my Ant script is
> called. I must limit my solution to that which I can put into my own
> Ant script.
>
> My challenge is to figure a way to run groovy 2.0 code. My attempt
> below fails to do this. I'm hoping someone will have a solution.
> Ideally, it will NOT involve using *exec *because in the groovy code I
> will be using AntBuilder to access various tasks, macros, etc. that
> are defined back on the Ant side and I want logging information to go
> to the same logfile as well.
>
> *Can anyone think of a way to execute some Groovy 2.0 code given that
> the classpath already includes a 1.7 Groovy jar file?*
>
> Thanks,
> Steve Amerige
> SAS Institute, Deployment Developer
>
> Note below that the Groovy system version is 1.7.10, not 2.0.1.
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <project name="Ant" default="main" basedir=".">
>
> <path id="my.classpath">
> <fileset dir="C:/test/groovy-2.0.1/embeddable">
> <include name="groovy-all-2.0.1.jar" />
> </fileset>
> </path>
>
> <taskdef
> name="groovy"
> classname="org.codehaus.groovy.ant.Groovy"
> classpath="C:/test/groovy-2.0.1/embeddable/groovy-all-2.0.1.jar"/>
>
> <target name="main">
> <groovy classpathref="my.classpath">
> println GroovySystem.getVersion()
> println GroovySystem.class.getClassLoader().getURLs().join("\n")
> </groovy>
> </target>
>
> </project>
>
>
> Buildfile: C:\test\build.xml
> main:
> [groovy] *1.7.10*
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-antlr.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-bcel.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-bsf.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-log4j.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-oro.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-regexp.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-apache-resolver.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-commons-logging.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-commons-net.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jai.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-javamail.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jdepend.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jmf.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-jsch.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-junit.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-launcher.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-netrexx.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-nodeps.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-starteam.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-stylebook.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-swing.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-trax.jar
> [groovy]
> file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-weblogic.jar
> [groovy]
> file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/84/1/.cp/lib/remoteAnt.jar
> [groovy]
> file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/772/1/.cp/lib/antdebug.jar
> [groovy]
> file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/772/1/.cp/lib/remote.jar
> [groovy]
> file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/1140/1/.cp/antlibs/remoteAnt.jar
> [groovy] file:/C:/Program%20Files/Java/jdk1.6.0_24/lib/tools.jar
> [groovy]
> file:/C:/eclipse/plugins/org.eclipse.swt.win32.win32.x86_64_3.6.2.v3659c.jar
> [groovy] file:/C:/test/ant-contrib/ant-contrib.jar
> [groovy]
> file:/C:/eclipse/plugins/org.codehaus.groovy_1.7.10.xx-20110918-1400-e36/lib/groovy-all-1.7.10.jar
> [groovy] file:/C:/test/json_0.2.0.0_SAS_20100917120500/JSON.jar
> BUILD SUCCESSFUL
> Total time: 1 second
>
>