Passing compile / runtime / compileOnly dependencies to ant taskdef?

I’m trying to invoke some ant tasks via a custom plugin. The actual classes needed for that task are loaded in my dependencies block. However, those classes are not passed to the ant runtime.

Is there a recommended method of passing the dependencies packages specified in my build.gradle to the ant runtime?

currently, when running ant.taskdef(name: "foo", classname: "baz.bar.Foo") I get “taskdef class baz.bar.Foo cannot be found using the classloader AntClassLoader

more specifically, I’m trying to invoke the weblogic wsdlc ant task, if anybody out there happened to have already implemented this :slight_smile:

See the pmd example from the Gradle Ant documentation

configurations {
    pmd
}
dependencies {
    pmd group: 'pmd', name: 'pmd', version: '4.2.5'
}
ant.taskdef(
   name: 'pmd',
   classname: 'net.sourceforge.pmd.ant.PMDTask',
   classpath: configurations.pmd.asPath
)
1 Like

ok - that makes sense.

what if the i need that reference in a separate .groovy / java file that is down in the src / buildSrc folder?

I’m assuming you’re talking about a plugin? Or maybe a custom task? If it’s groovy, a simple way is to wrap in a project.with {...} closure. Eg:

class MyPlugin implements Plugin<Project> {
   void apply(Project project) {
      project.with {
          configurations {...} 
          dependencies {...} 
          task foo {
              doLast {
                 ant.taskdef {...} 
              } 
          } 
      } 
   } 
}

If its java it will be more verbose

project.getConfigurations().create("pmd");
project.getDependencies().add("pmd", "pmd:pmd:4.2.5");
FooTask foo = project.getTasks().create("foo", FooTask.class);
foo.setBar("baz");
//etc