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 =

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

The antClassLoader is from type VisitableURLClassLoader everything is OK

val antClassLoader: 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?


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.