Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 20347

Gradle plugin with reflections

$
0
0

Hi every body,

here is the way I get URLs:

        final URL[] urls = project.sourceSets.main.output.classesDirs.files.collect { File dir ->
            dir.listFiles()
        }.flatten().collect {
            getLogger().lifecycle(
                    "File?: " + it
            )
            if (it != null) {
                it.toURI().toURL()
            }
        }.findAll {
            it != null
        } as URL[]

Notive that project.sourceSets.main.output.classesDir does not exist anymore.

Here is the Kotlin way I configure Reflections:

    /**
     * Secondary constructor with reflections configuration.
     *
     * @param packageName The name of the package to scan.
     * @param configuration The [Configuration] to use.
     */
    constructor(
        packageName: String,
        configuration: Configuration
    ) : this(
        packageName = packageName,
        reflections = Reflections(configuration)
    )

    /**
     * Secondary constructor.
     *
     * @param packageName The name of the package to scan.
     * @param classLoader The [ClassLoader] to use.
     */
    constructor(
        packageName: String,
        classLoader: ClassLoader
    ) : this(
        packageName = packageName,
        configuration = ConfigurationBuilder(
        ).setUrls(
            ClasspathHelper.forClassLoader(classLoader)
        ).setScanners(
            SubTypesScanner(false),
            TypeAnnotationsScanner()
        ).addClassLoader(
            classLoader
        )
    )

    /**
     * Secondary constructor.
     *
     * @param packageName The name of the package to scan.
     * @param urls The [URL] array to use.
     */
    constructor(
        packageName: String,
        urls: Array<URL>
    ) : this(
        packageName = packageName,
        classLoader = URLClassLoader(urls)
    )

The, when performing:

        val list = reflections.getSubTypesOf(
            Any::class.java
        ).asIterable().toList()

I get the following error:

Caused by: java.lang.ClassNotFoundException: com.github.roroche.eoplantumlbuilder.classes.ClsFiltered

The plugin code is here: https://github.com/RoRoche/plantuml-gradle-plugin
The project including it is here: https://github.com/RoRoche/eo-plantuml-builder

Any idea?


Viewing all articles
Browse latest Browse all 20347

Trending Articles