vendredi 10 août 2018

Kotlin classes cannot be found when reflecting filepaths to source directories or jars

Looking to use the following line to pull a list of class names from Kotlin source...

    Reflections.getSubTypesOf(Any::class.java)

However I receive a message that Kotlin class files aren't being seen when I run the following script...

    val classLoader = URLClassLoader(this.getDirectoryUrls(), null)
    System.out.println("retrieved class loader")

    val config = getConfig(classLoader)
    System.out.println("retrieved source config")

    val reflections = Reflections(config)
    System.out.println("retrieved reflections")

    //For 3 paths: Reflections took 3 ms to scan 3 urls, producing 0 keys and 0 values

Below is my config... ideas?

private fun getConfig(classLoader: ClassLoader): ConfigurationBuilder {
    val config = ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(classLoader))
    //                .setScanners(SubTypesScanner(false), ResourcesScanner())

    if (!packagePath.isNullOrBlank()){
        System.out.println("looking in package [$packagePath]")
        config.filterInputsBy(FilterBuilder().include(FilterBuilder.prefix(packagePath)))
    }

    config.addClassLoader(classLoader)
    config.setScanners(SubTypesScanner(), TypeAnnotationsScanner())

    return config
}





Aucun commentaire:

Enregistrer un commentaire