# Extend JavaExec task with additional classpath entry

**URL:** <https://discuss.gradle.org/t/extend-javaexec-task-with-additional-classpath-entry/30014>\
**Category:** Help/Discuss\
**Created:** [December 30, 2018, 11:47am UTC](https://discuss.gradle.org/t/extend-javaexec-task-with-additional-classpath-entry/30014 "2018-12-30T11:47:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HoldYourWaffle](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/holdyourwaffle/32/7407_2.png) [@HoldYourWaffle](https://discuss.gradle.org/u/HoldYourWaffle)\
**Post date:** [December 30, 2018, 11:47am UTC](https://discuss.gradle.org/t/extend-javaexec-task-with-additional-classpath-entry/30014/1 "2018-12-30T11:47:04Z")

</div>

I have a task of type JavaExec that does a lot of complicated steps in order to compile & run the application. This task is generated by a plugin outside of my control.

I want to create another task that “extends” this task, adding an extra dependency configuration. This configuration stores some dependencies that should only be included for this specific task.

Is there an easy way for me to create such a task, or do I have to copy over all configuration properties (by which I mean stuff like main class, classpath, commandline arguments) manually?

I found [this topic](https://discuss.gradle.org/t/is-it-possible-to-copy-the-configuration-of-a-task-of-a-given-type-into-another-task-of-the-same-type/3697) which says that this isn’t possible, but that one is over 5 years old. Has gradle added this functionality?

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [December 31, 2018, 10:18pm UTC](https://discuss.gradle.org/t/extend-javaexec-task-with-additional-classpath-entry/30014/2 "2018-12-31T22:18:49Z")

</div>

It is still the same, however you could potentially solve your problem using a rule

```groovy
tasks.addRule 'my-javaexec-tasks', { taskName ->
  if(taskName == 'task1' || taskName == 'task2') {
    JavaExec newTask = project.tasks.create( taskName, JavaExec ) 
    newTask.configure {
      // configure common properties for both tasks
    }
    if(taskName == 'task2') {
      // configure additional dependency configuration
    }
    return newTask
  }
  null
}

```
