Let your task implement the org.apache.tools.ant.TaskContainer interface, write your own addTask(Task task) method.
For example (it should only take a task named "java"):
private List<Task> _nestedTask = new ArrayList<>(); public void addTask(Task task) { if (task.getTaskName().equals("java")) { _nestedTasks.add(task); } else { throw new BuildException("Support only nested <java> task."); } }
Please note that if you write multiple nested <java> tasks in your build file, you need to handle them by your self. To execute the nested <java> tasks, just iterate through the list and call execute() method for each task.
Update:
When a nested task is added, it doesn't run automatically. It won't even run if its execute() method is not called in your custom task.
So... A very basic and simple example:
// your custom task's execute... public void execute() { //do something for (Task task : _nestedTask) { task.perform(); // here the nested task is executed. } //do something }
Run nested task in custom taskor similar... may draw more attention.