Extend JavaExec task with additional classpath entry

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 which says that this isn’t possible, but that one is over 5 years old. Has gradle added this functionality?

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

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