Passing compile / runtime / compileOnly dependencies to ant taskdef?

plugins

(Clay Mitchell) #1

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


(Clay Mitchell) #2

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


(uklance) #3

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
)

(Clay Mitchell) #4

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?


(uklance) #5

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