Java Mailing List Archive

http://www.ant-tasks.com/

Home » Ant Users List »

Taskdef and custom classloader

Hans Dockter

2008-05-03


With a Groovy based build tool I have the following problem.

The JVM this build tool is running in, is started with a jar in the
classpath that contains a certain Ant task (groovyc). What I need now is a
way to define a groovyc task from _another_ jar with a different version.

I try to do this the following way:

<taskdef name="isolatedLoader"
classname="org.gradle.api.tasks.util.IsolatedLoader"/>
<isolatedLoader ref="loader">
   <classpath path='path+with_other_groovyc_and_ant'/>
</isolatedLoader>
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc"
loaderref="loader"/>

The lsolatedLoader class looks like this:

class IsolatedLoader extends MatchingTask {
  private String name;
  private Path taskClasspath;

  /**
  * sets the name of the reference which should store the Loader
  */
  public void setRef(String n){
    name = n;
  }

  public void execute() throws BuildException {
    Project project = getProject();
    AntClassLoader loader = new AntClassLoader();
    loader.setClassPath(taskClasspath);
    loader.setParent(getClass().classLoader.systemClassLoader.parent))
    project.addReference(name,loader);
  }
...
}

When I now execute the groovyc task, Ant can't find it.

If I try a different way of achieving my goal, this is when I define the
IsolatedLoader like:

public void execute() throws BuildException {
Project project = getProject();
AntClassLoader loader = new AntClassLoader();
loader.setClassPath(taskClasspath);
loader.setParentFirst(false);
project.addReference(name,loader);

I do get ClassCastExceptions.

Has anybody an idea how I completely isolate a taskdef from an existing
classpath?

- Hans

--
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.