How to get VisitableURLClassLoader with Kotiln DSL?

Hello All,
I have this lines of working groovy code and I would like to convert it to kotlin

ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader

configurations.antClasspath.each { File jar ->
    println "Adding to ant classpath : " + jar.absolutePath
    println(antClassLoader.getClass().getName()) //output: org.gradle.internal.classloader.VisitableURLClassLoader
    antClassLoader.addURL(jar.toURI().toURL())
}

The antClassLoader is from type VisitableURLClassLoader everything is OK

val antClassLoader: ClassLoader = org.apache.tools.ant.Project::class.java.classLoader

configurations["antClasspath"].forEach { jar: File ->
  logger.log(LogLevel.LIFECYCLE, "Adding to ant classpath : " + jar.absolutePath)
  antClassLoader.addURL(jar.toURI().toURL()) //does not compile because type is ClassLoader
}

Any ideas?

Tom

Just cast it to VisitableURLClassLoader if you insist.
But as that class is a Gradle internal class, it is questionable whether that is a good idea. :wink:
The Groovy dynamicness and duck-typing just hid that code smell pretty well.

You should probably just don’t try to do that, but use supported ways to do whatever you intend to do.