# Passing compile / runtime / compileOnly dependencies to ant taskdef?

**URL:** <https://discuss.gradle.org/t/passing-compile-runtime-compileonly-dependencies-to-ant-taskdef/29760>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [December 5, 2018, 10:33pm UTC](https://discuss.gradle.org/t/passing-compile-runtime-compileonly-dependencies-to-ant-taskdef/29760 "2018-12-05T22:33:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![claym](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/claym/32/7380_2.png) [@claym](https://discuss.gradle.org/u/claym)\
**Post date:** [December 5, 2018, 10:33pm UTC](https://discuss.gradle.org/t/passing-compile-runtime-compileonly-dependencies-to-ant-taskdef/29760/1 "2018-12-05T22:33:12Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![claym](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/claym/32/7380_2.png) [@claym](https://discuss.gradle.org/u/claym)\
**Post date:** [December 5, 2018, 10:34pm UTC](https://discuss.gradle.org/t/passing-compile-runtime-compileonly-dependencies-to-ant-taskdef/29760/2 "2018-12-05T22:34:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [December 5, 2018, 11:27pm UTC](https://discuss.gradle.org/t/passing-compile-runtime-compileonly-dependencies-to-ant-taskdef/29760/3 "2018-12-05T23:27:26Z")

</div>

See the pmd example from the [Gradle Ant documentation](https://docs.gradle.org/current/userguide/ant.html#sec:using_ant_tasks)

```gradle
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
)

```

---

<div class="post-metadata">

**Author:** ![claym](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/claym/32/7380_2.png) [@claym](https://discuss.gradle.org/u/claym)\
**Post date:** [December 6, 2018, 6:32pm UTC](https://discuss.gradle.org/t/passing-compile-runtime-compileonly-dependencies-to-ant-taskdef/29760/4 "2018-12-06T18:32:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [December 7, 2018, 11:17pm UTC](https://discuss.gradle.org/t/passing-compile-runtime-compileonly-dependencies-to-ant-taskdef/29760/5 "2018-12-07T23:17:36Z")

</div>

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:

```groovy
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

```java
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

```
