It's connected with. I am trying to dynamically add maven-ant -tasks jars using Grape, simulating this:
<taskdef uri="antlib:org.apache.maven.artifact.ant" resource="org/apache/maven/artifact/ant/antlib.xml" classpathref="ant.classpath" />
I tried using Grape.grab () to make maven-ant -tasks available to AntBuilder as follows:
import groovy.grape.Grape println "grab..." Grape.grab(group:'ant', module:'ant', version:'1.7.0', classLoader:this.class.classLoader.rootLoader) Grape.grab(group: 'org.apache.maven', module: 'maven-ant-tasks', version: '2.0.9') println "ant taskdef..." def ant = new AntBuilder() ant.taskdef (resource: "org/apache/maven/artifact/ant/antlib.xml" )
but this does not work, because Grape adds modules to another ClassLoader from the one that uses the ANT engine. So, I took the advice of this question about the AntBuilder path object and made Grape to use the root class of ClassLoader:
import groovy.grape.Grape println "grab..." Grape.grab(group:'ant', module:'ant', version:'1.7.0', classLoader:this.class.classLoader.rootLoader) Grape.grab(group: 'org.apache.maven', module: 'maven-ant-tasks', version: '2.0.9', classLoader: this.class.classLoader.rootLoader) println "ant taskdef..." def ant = new AntBuilder() ant.taskdef (resource: "org/apache/maven/artifact/ant/antlib.xml" )
Now it raises a LinkageError:
Caught: : java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Locator used in the signature at test.mavenanttasks.run(mavenanttasks.groovy:11)
Any hints on getting this to work? Or is all this a bad idea?