Using ant taskdef for optional ant tasks

I’m currently migrating an Ant-based build to Gradle; for now I’m mostly just importing the existing build file via ant.importBuild(). This build file uses the junit task, which is an optional ant task, so it’s not available by default. I managed to make it work using ant.taskdef(), as described in https://discuss.gradle.org/t/ant-imports-taskdefs-failed-to-create-task-or-type-junit/7517/5.

While this does work, it results in the message “Trying to override old definition of datatype junit”, which I consider a bit worrying - in particular the word “trying”, which seems to suggest that the call is intercepted somehow rather than actually executed.

Is there a better/cleaner way to make the ant-junit jar available to the build?